Kaydet (Commit) 20054477 authored tarafından Petri Lehtinen's avatar Petri Lehtinen

Issue #15132: Allow a list for the defaultTest argument of unittest.TestProgram

Patch by Jyrki Pulliainen
üst d784e53d
......@@ -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):
......
......@@ -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,
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment