Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8fd396b

Browse files
committed
Issue 17502: unittest discovery should use self.testLoader
1 parent 6c22b1d commit 8fd396b

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

Lib/unittest/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ def createTests(self):
197197
self.test = self.testLoader.loadTestsFromNames(self.testNames,
198198
self.module)
199199

200-
def _do_discovery(self, argv, Loader=loader.TestLoader):
200+
def _do_discovery(self, argv, Loader=None):
201+
if Loader is None:
202+
Loader = self.testLoader
203+
201204
# handle command line args for test discovery
202205
self.progName = '%s discover' % self.progName
203206
import optparse

Lib/unittest/test/test_discovery.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,26 @@ def usageExit():
253253

254254
program = TestableTestProgram()
255255
program.usageExit = usageExit
256+
program.testLoader = None
256257

257258
with self.assertRaises(Stop):
258259
# too many args
259260
program._do_discovery(['one', 'two', 'three', 'four'])
260261

261262

263+
def test_command_line_handling_do_discovery_uses_default_loader(self):
264+
program = object.__new__(unittest.TestProgram)
265+
266+
class Loader(object):
267+
args = []
268+
def discover(self, start_dir, pattern, top_level_dir):
269+
self.args.append((start_dir, pattern, top_level_dir))
270+
return 'tests'
271+
272+
program.testLoader = Loader
273+
program._do_discovery(['-v'])
274+
self.assertEqual(Loader.args, [('.', 'test*.py', None)])
275+
262276
def test_command_line_handling_do_discovery_calls_loader(self):
263277
program = TestableTestProgram()
264278

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ Core and Builtins
221221
Library
222222
-------
223223

224+
- Issue #17502: unittest discovery should use self.testLoader.
225+
224226
- Issue #17141: random.vonmisesvariate() no more hangs for large kappas.
225227

226228
- Issue #17149: Fix random.vonmisesvariate to always return results in

0 commit comments

Comments
 (0)