mirror of
https://github.com/python/cpython.git
synced 2024-11-24 02:15:30 +08:00
Issue 17502: unittest discovery should use self.testLoader
This commit is contained in:
parent
6c22b1d760
commit
8fd396bd22
@ -197,7 +197,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
|
||||
|
@ -253,12 +253,26 @@ class TestDiscovery(unittest.TestCase):
|
||||
|
||||
program = TestableTestProgram()
|
||||
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 = TestableTestProgram()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user