Commit cb66ee7f authored by Michael Foord's avatar Michael Foord

Issue 17502: unittest discovery should use self.testLoader

parent 65d56390
...@@ -157,7 +157,10 @@ class TestProgram(object): ...@@ -157,7 +157,10 @@ class TestProgram(object):
self.test = self.testLoader.loadTestsFromNames(self.testNames, self.test = self.testLoader.loadTestsFromNames(self.testNames,
self.module) 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 # handle command line args for test discovery
self.progName = '%s discover' % self.progName self.progName = '%s discover' % self.progName
import optparse import optparse
......
...@@ -220,12 +220,26 @@ class TestDiscovery(unittest.TestCase): ...@@ -220,12 +220,26 @@ class TestDiscovery(unittest.TestCase):
program = object.__new__(unittest.TestProgram) program = object.__new__(unittest.TestProgram)
program.usageExit = usageExit program.usageExit = usageExit
program.testLoader = None
with self.assertRaises(Stop): with self.assertRaises(Stop):
# too many args # too many args
program._do_discovery(['one', 'two', 'three', 'four']) 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): def test_command_line_handling_do_discovery_calls_loader(self):
program = object.__new__(unittest.TestProgram) program = object.__new__(unittest.TestProgram)
......
...@@ -202,6 +202,8 @@ Core and Builtins ...@@ -202,6 +202,8 @@ Core and Builtins
Library Library
------- -------
- Issue #17502: unittest discovery should use self.testLoader.
- Issue #17141: random.vonmisesvariate() no more hangs for large kappas. - Issue #17141: random.vonmisesvariate() no more hangs for large kappas.
- Issue #17149: Fix random.vonmisesvariate to always return results in - Issue #17149: Fix random.vonmisesvariate to always return results in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment