summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2013-02-23 17:52:51 (GMT)
committerPetri Lehtinen <petri@digip.org>2013-02-23 17:55:49 (GMT)
commit20054477f4671150e098b519dc1b85d7db6d27ab (patch)
treee2923f8ac088152e4919f2726273bc21c2d52b0a /Lib/unittest
parentd784e53d9683b26822cc08b02a4bc6cb5a482e66 (diff)
downloadcpython-20054477f4671150e098b519dc1b85d7db6d27ab.zip
cpython-20054477f4671150e098b519dc1b85d7db6d27ab.tar.gz
cpython-20054477f4671150e098b519dc1b85d7db6d27ab.tar.bz2
Issue #15132: Allow a list for the defaultTest argument of unittest.TestProgram
Patch by Jyrki Pulliainen
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/main.py5
-rw-r--r--Lib/unittest/test/test_program.py35
2 files changed, 39 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,