summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2013-02-11 00:28:02 (GMT)
committerMichael Foord <michael@voidspace.org.uk>2013-02-11 00:28:02 (GMT)
commit4e08f786f042f09454939a1a7a16ccea70488093 (patch)
tree28b1604a92c438f7393920472bc750fec9468e08
parenta7b5e82ff03a25c35ea0e0b124a7d113ffa0cb3a (diff)
parenta23a39c07d3027e5139cc6127783cab23ca1a511 (diff)
downloadcpython-4e08f786f042f09454939a1a7a16ccea70488093.zip
cpython-4e08f786f042f09454939a1a7a16ccea70488093.tar.gz
cpython-4e08f786f042f09454939a1a7a16ccea70488093.tar.bz2
Merge. Closes issue 17052.
-rw-r--r--Lib/unittest/main.py6
-rw-r--r--Lib/unittest/test/test_discovery.py14
-rw-r--r--Misc/NEWS2
3 files changed, 21 insertions, 1 deletions
diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py
index a25a2f8..061916c 100644
--- a/Lib/unittest/main.py
+++ b/Lib/unittest/main.py
@@ -175,6 +175,7 @@ class TestProgram(object):
self.module)
def _getOptParser(self):
+ import optparse
parser = optparse.OptionParser()
parser.prog = self.progName
parser.add_option('-v', '--verbose', dest='verbose', default=False,
@@ -219,7 +220,10 @@ class TestProgram(object):
parser.add_option('-t', '--top-level-directory', dest='top', default=None,
help='Top level directory of project (defaults to start directory)')
- 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
parser = self._getOptParser()
diff --git a/Lib/unittest/test/test_discovery.py b/Lib/unittest/test/test_discovery.py
index e688f8e..eba269f 100644
--- a/Lib/unittest/test/test_discovery.py
+++ b/Lib/unittest/test/test_discovery.py
@@ -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()
diff --git a/Misc/NEWS b/Misc/NEWS
index 34ded23..4871a4f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -250,6 +250,8 @@ Core and Builtins
Library
-------
+- Issue #17502: unittest discovery should use self.testLoader.
+
- Issue #4591: Uid and gid values larger than 2**31 are supported now.
- Issue #17141: random.vonmisesvariate() no more hangs for large kappas.