[Python-checkins] cpython (2.7): Issue 17502: unittest discovery should use self.testLoader

michael.foord python-checkins at python.org
Mon Feb 11 01:28:24 CET 2013


http://hg.python.org/cpython/rev/1ccf0756a13d
changeset:   82149:1ccf0756a13d
branch:      2.7
parent:      82139:0f9113e1b541
user:        Michael Foord <michael at voidspace.org.uk>
date:        Sun Feb 10 23:59:46 2013 +0000
summary:
  Issue 17502: unittest discovery should use self.testLoader

files:
  Lib/unittest/main.py                |   5 ++++-
  Lib/unittest/test/test_discovery.py |  14 ++++++++++++++
  Misc/NEWS                           |   2 ++
  3 files changed, 20 insertions(+), 1 deletions(-)


diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py
--- a/Lib/unittest/main.py
+++ b/Lib/unittest/main.py
@@ -157,7 +157,10 @@
             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
--- a/Lib/unittest/test/test_discovery.py
+++ b/Lib/unittest/test/test_discovery.py
@@ -220,12 +220,26 @@
 
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -202,6 +202,8 @@
 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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list