From: Michael Foord Date: Sun, 10 Feb 2013 23:59:46 +0000 (+0000) Subject: Issue 17502: unittest discovery should use self.testLoader X-Git-Tag: v2.7.4rc1~126 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb66ee7f56fe66d4b4cb7bc6abe6e1314e98b5c9;p=python Issue 17502: unittest discovery should use self.testLoader --- diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py index 3396bb0ab6..1e001a6a26 100644 --- a/Lib/unittest/main.py +++ b/Lib/unittest/main.py @@ -157,7 +157,10 @@ class TestProgram(object): self.test = self.testLoader.loadTestsFromNames(self.testNames, self.module) - def _do_discovery(self, argv, Loader=loader.TestLoader): + def _do_discovery(self, argv, Loader=None): + if Loader is None: + Loader = self.testLoader + # handle command line args for test discovery self.progName = '%s discover' % self.progName import optparse diff --git a/Lib/unittest/test/test_discovery.py b/Lib/unittest/test/test_discovery.py index 1155de116f..3dec2ee57e 100644 --- a/Lib/unittest/test/test_discovery.py +++ b/Lib/unittest/test/test_discovery.py @@ -220,12 +220,26 @@ class TestDiscovery(unittest.TestCase): program = object.__new__(unittest.TestProgram) program.usageExit = usageExit + program.testLoader = None with self.assertRaises(Stop): # too many args program._do_discovery(['one', 'two', 'three', 'four']) + def test_command_line_handling_do_discovery_uses_default_loader(self): + program = object.__new__(unittest.TestProgram) + + class Loader(object): + args = [] + def discover(self, start_dir, pattern, top_level_dir): + self.args.append((start_dir, pattern, top_level_dir)) + return 'tests' + + program.testLoader = Loader + program._do_discovery(['-v']) + self.assertEqual(Loader.args, [('.', 'test*.py', None)]) + def test_command_line_handling_do_discovery_calls_loader(self): program = object.__new__(unittest.TestProgram) diff --git a/Misc/NEWS b/Misc/NEWS index 9989b7b10c..d5186d3353 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -202,6 +202,8 @@ Core and Builtins Library ------- +- Issue #17502: unittest discovery should use self.testLoader. + - Issue #17141: random.vonmisesvariate() no more hangs for large kappas. - Issue #17149: Fix random.vonmisesvariate to always return results in