summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2013-02-10 23:59:46 (GMT)
committerMichael Foord <michael@voidspace.org.uk>2013-02-10 23:59:46 (GMT)
commitcb66ee7f56fe66d4b4cb7bc6abe6e1314e98b5c9 (patch)
treeae5778d85c5fad29f616c33cb6344eddd6d74f54 /Lib/unittest
parent65d56390bbf74553221dd94123c9f04776c6f8cb (diff)
downloadcpython-cb66ee7f56fe66d4b4cb7bc6abe6e1314e98b5c9.zip
cpython-cb66ee7f56fe66d4b4cb7bc6abe6e1314e98b5c9.tar.gz
cpython-cb66ee7f56fe66d4b4cb7bc6abe6e1314e98b5c9.tar.bz2
Issue 17502: unittest discovery should use self.testLoader
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/main.py5
-rw-r--r--Lib/unittest/test/test_discovery.py14
2 files changed, 18 insertions, 1 deletions
diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py
index 3396bb0..1e001a6 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 1155de1..3dec2ee 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)