Merged revisions 79265-79266 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79265 | michael.foord | 2010-03-21 20:01:34 -0500 (Sun, 21 Mar 2010) | 1 line

  -f/--failfast command line option for unittest. Issue 8074. Documentation still needed. Plus minor change to test_unittest to allow it to be run with python -m test.unittest
........
  r79266 | michael.foord | 2010-03-21 20:02:23 -0500 (Sun, 21 Mar 2010) | 1 line

  Fix failing test committed by accident.
........
This commit is contained in:
Benjamin Peterson 2010-03-22 01:13:48 +00:00
parent dccc1fcfaf
commit 8769fd8a17
4 changed files with 85 additions and 25 deletions

View file

@ -2106,6 +2106,38 @@ class Test_TestResult(TestCase):
Frame.tb_frame.f_globals['__unittest'] = True
self.assertTrue(result._is_relevant_tb_level(Frame))
def testFailFast(self):
result = unittest.TestResult()
result._exc_info_to_string = lambda *_: ''
result.failfast = True
result.addError(None, None)
self.assertTrue(result.shouldStop)
result = unittest.TestResult()
result._exc_info_to_string = lambda *_: ''
result.failfast = True
result.addFailure(None, None)
self.assertTrue(result.shouldStop)
result = unittest.TestResult()
result._exc_info_to_string = lambda *_: ''
result.failfast = True
result.addUnexpectedSuccess(None)
self.assertTrue(result.shouldStop)
result = unittest.TestResult()
result._exc_info_to_string = lambda *_: ''
result.failfast = True
result.addExpectedFailure(None, None)
self.assertTrue(result.shouldStop)
def testFailFastSetByRunner(self):
runner = unittest.TextTestRunner(stream=io.StringIO(), failfast=True)
def test(result):
self.assertTrue(result.failfast)
result = runner.run(test)
classDict = dict(unittest.TestResult.__dict__)
for m in ('addSkip', 'addExpectedFailure', 'addUnexpectedSuccess',
'__init__'):
@ -2181,21 +2213,23 @@ class Foo(unittest.TestCase):
class Bar(Foo):
def test2(self): pass
class LoggingTestCase(unittest.TestCase):
"""A test case which logs its calls."""
def getLoggingTestCase():
class LoggingTestCase(unittest.TestCase):
"""A test case which logs its calls."""
def __init__(self, events):
super(LoggingTestCase, self).__init__('test')
self.events = events
def __init__(self, events):
super(LoggingTestCase, self).__init__('test')
self.events = events
def setUp(self):
self.events.append('setUp')
def setUp(self):
self.events.append('setUp')
def test(self):
self.events.append('test')
def test(self):
self.events.append('test')
def tearDown(self):
self.events.append('tearDown')
def tearDown(self):
self.events.append('tearDown')
return LoggingTestCase
class ResultWithNoStartTestRunStopTestRun(object):
"""An object honouring TestResult before startTestRun/stopTestRun."""
@ -2322,7 +2356,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
events = []
result = LoggingResult(events)
class Foo(LoggingTestCase):
class Foo(getLoggingTestCase()):
def setUp(self):
super(Foo, self).setUp()
raise RuntimeError('raised by Foo.setUp')
@ -2335,7 +2369,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
def test_run_call_order__error_in_setUp_default_result(self):
events = []
class Foo(LoggingTestCase):
class Foo(getLoggingTestCase()):
def defaultTestResult(self):
return LoggingResult(self.events)
@ -2359,7 +2393,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
events = []
result = LoggingResult(events)
class Foo(LoggingTestCase):
class Foo(getLoggingTestCase()):
def test(self):
super(Foo, self).test()
raise RuntimeError('raised by Foo.test')
@ -2374,7 +2408,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
def test_run_call_order__error_in_test_default_result(self):
events = []
class Foo(LoggingTestCase):
class Foo(getLoggingTestCase()):
def defaultTestResult(self):
return LoggingResult(self.events)
@ -2398,7 +2432,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
events = []
result = LoggingResult(events)
class Foo(LoggingTestCase):
class Foo(getLoggingTestCase()):
def test(self):
super(Foo, self).test()
self.fail('raised by Foo.test')
@ -2411,7 +2445,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
# "When a test fails with a default result stopTestRun is still called."
def test_run_call_order__failure_in_test_default_result(self):
class Foo(LoggingTestCase):
class Foo(getLoggingTestCase()):
def defaultTestResult(self):
return LoggingResult(self.events)
def test(self):
@ -2435,7 +2469,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
events = []
result = LoggingResult(events)
class Foo(LoggingTestCase):
class Foo(getLoggingTestCase()):
def tearDown(self):
super(Foo, self).tearDown()
raise RuntimeError('raised by Foo.tearDown')
@ -2448,7 +2482,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
# "When tearDown errors with a default result stopTestRun is still called."
def test_run_call_order__error_in_tearDown_default_result(self):
class Foo(LoggingTestCase):
class Foo(getLoggingTestCase()):
def defaultTestResult(self):
return LoggingResult(self.events)
def tearDown(self):