Ticket #26659: patch.diff

File patch.diff, 3.0 KB (added by Antonio Piraino, 8 years ago)
  • django/core/management/commands/test.py

    diff --git a/django/core/management/commands/test.py b/django/core/management/commands/test.py
    index 73796fe..2cafa40 100644
    a b class Command(BaseCommand):  
    5252                 'with LiveServerTestCase) is expected to run from. The '
    5353                 'default value is localhost:8081-8179.',
    5454        )
    55 
     55        parser.add_argument(
     56            '--method-filter', dest='methodfilter',
     57            action='store', default=None,
     58            help='csv list of test methods to run out of the TestSuite created, discard the others.'
     59        )
    5660        test_runner_class = get_runner(settings, self.test_runner)
    5761
    5862        if hasattr(test_runner_class, 'add_arguments'):
    class Command(BaseCommand):  
    6973        del options['liveserver']
    7074
    7175        test_runner = TestRunner(**options)
    72         failures = test_runner.run_tests(test_labels)
     76        failures = test_runner.run_tests(test_labels, method_filter=options.get('methodfilter'))
    7377
    7478        if failures:
    7579            sys.exit(bool(failures))
  • django/test/runner.py

    diff --git a/django/test/runner.py b/django/test/runner.py
    index c60f5e8..310ce1e 100644
    a b class DebugSQLTextTestResult(unittest.TextTestResult):  
    6363            self.stream.writeln("%s" % sql_debug)
    6464
    6565
     66class SimpleTextTestResult(DebugSQLTextTestResult):
     67    def __init__(self, stream, descriptions, verbosity):
     68        super(SimpleTextTestResult, self).__init__(stream, descriptions, verbosity)
     69
     70    def printErrorList(self, flavour, errors):
     71        for test, err, sql in errors:
     72            self.stream.writeln(self.separator1)
     73            self.stream.writeln("%s: %s" % (flavour, self.getDescription(test)))
     74            self.stream.writeln("Path: %s" % test.id())
     75            self.stream.writeln(self.separator1)
     76            self.stream.writeln("%s" % err)
     77
     78
    6679class RemoteTestResult(object):
    6780    """
    6881    Record information about which tests have succeeded and which have failed.
    class DiscoverRunner(object):  
    500513        )
    501514
    502515    def get_resultclass(self):
    503         return DebugSQLTextTestResult if self.debug_sql else None
     516        return DebugSQLTextTestResult if self.debug_sql else SimpleTextTestResult
    504517
    505518    def run_suite(self, suite, **kwargs):
    506519        resultclass = self.get_resultclass()
    class DiscoverRunner(object):  
    546559        """
    547560        self.setup_test_environment()
    548561        suite = self.build_suite(test_labels, extra_tests)
     562        if kwargs.get('method_filter'):
     563            only_these_methods = kwargs.get('method_filter').split(',')
     564            new_suite = unittest.TestSuite()
     565            for t in suite:
     566                if t._testMethodName in only_these_methods:
     567                    new_suite.addTest(t)
     568            suite = new_suite
     569            del new_suite
    549570        old_config = self.setup_databases()
    550571        result = self.run_suite(suite)
    551572        self.teardown_databases(old_config)
Back to Top