summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/unittest/main.py5
-rw-r--r--Lib/unittest/test/test_program.py35
-rw-r--r--Misc/NEWS3
3 files changed, 42 insertions, 1 deletions
diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py
index ead6493..edb141a 100644
--- a/Lib/unittest/main.py
+++ b/Lib/unittest/main.py
@@ -164,7 +164,10 @@ class TestProgram(object):
# to support python -m unittest ...
self.module = None
else:
- self.testNames = (self.defaultTest,)
+ if isinstance(self.defaultTest, str):
+ self.testNames = (self.defaultTest,)
+ else:
+ self.testNames = list(self.defaultTest)
self.createTests()
def createTests(self):
diff --git a/Lib/unittest/test/test_program.py b/Lib/unittest/test/test_program.py
index 9794868..8e02f3c 100644
--- a/Lib/unittest/test/test_program.py
+++ b/Lib/unittest/test/test_program.py
@@ -64,6 +64,41 @@ class Test_TestProgram(unittest.TestCase):
return self.suiteClass(
[self.loadTestsFromTestCase(Test_TestProgram.FooBar)])
+ def loadTestsFromNames(self, names, module):
+ return self.suiteClass(
+ [self.loadTestsFromTestCase(Test_TestProgram.FooBar)])
+
+ def test_defaultTest_with_string(self):
+ class FakeRunner(object):
+ def run(self, test):
+ self.test = test
+ return True
+
+ old_argv = sys.argv
+ sys.argv = ['faketest']
+ runner = FakeRunner()
+ program = unittest.TestProgram(testRunner=runner, exit=False,
+ defaultTest='unittest.test',
+ testLoader=self.FooBarLoader())
+ sys.argv = old_argv
+ self.assertEquals(('unittest.test',), program.testNames)
+
+ def test_defaultTest_with_iterable(self):
+ class FakeRunner(object):
+ def run(self, test):
+ self.test = test
+ return True
+
+ old_argv = sys.argv
+ sys.argv = ['faketest']
+ runner = FakeRunner()
+ program = unittest.TestProgram(
+ testRunner=runner, exit=False,
+ defaultTest=['unittest.test', 'unittest.test2'],
+ testLoader=self.FooBarLoader())
+ sys.argv = old_argv
+ self.assertEquals(['unittest.test', 'unittest.test2'],
+ program.testNames)
def test_NonExit(self):
program = unittest.main(exit=False,
diff --git a/Misc/NEWS b/Misc/NEWS
index a2777ce..e048d6d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -260,6 +260,9 @@ Core and Builtins
Library
-------
+- Issue #15132: Allow a list for the defaultTest argument of
+ unittest.TestProgram. Patch by Jyrki Pulliainen.
+
- Issue #17225: JSON decoder now counts columns in the first line starting
with 1, as in other lines.