[Python-checkins] cpython (merge 3.4 -> default): Issue #22894: TestCase.subTest() would cause the test suite to be stopped when

antoine.pitrou python-checkins at python.org
Sun Nov 23 16:01:30 CET 2014


https://hg.python.org/cpython/rev/04103cece49d
changeset: 93547:04103cece49d
parent: 93545:334659e8a625
parent: 93546:993e8f795194
user: Antoine Pitrou <solipsis at pitrou.net>
date: Sun Nov 23 15:56:41 2014 +0100
summary:
 Issue #22894: TestCase.subTest() would cause the test suite to be stopped when in failfast mode, even in the absence of failures.
files:
 Lib/unittest/result.py | 3 +-
 Lib/unittest/test/test_case.py | 28 ++++++++++++++++++++++
 Misc/NEWS | 3 ++
 3 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py
--- a/Lib/unittest/result.py
+++ b/Lib/unittest/result.py
@@ -121,7 +121,6 @@
 self.failures.append((test, self._exc_info_to_string(err, test)))
 self._mirrorOutput = True
 
- @failfast
 def addSubTest(self, test, subtest, err):
 """Called at the end of a subtest.
 'err' is None if the subtest ended successfully, otherwise it's a
@@ -130,6 +129,8 @@
 # By default, we don't do anything with successful subtests, but
 # more sophisticated test results might want to record them.
 if err is not None:
+ if getattr(self, 'failfast', False):
+ self.stop()
 if issubclass(err[0], test.failureException):
 errors = self.failures
 else:
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -397,6 +397,34 @@
 Foo(events).run(result)
 self.assertEqual(events, expected)
 
+ def test_subtests_failfast(self):
+ # Ensure proper test flow with subtests and failfast (issue #22894)
+ events = []
+
+ class Foo(unittest.TestCase):
+ def test_a(self):
+ with self.subTest():
+ events.append('a1')
+ events.append('a2')
+
+ def test_b(self):
+ with self.subTest():
+ events.append('b1')
+ with self.subTest():
+ self.fail('failure')
+ events.append('b2')
+
+ def test_c(self):
+ events.append('c')
+
+ result = unittest.TestResult()
+ result.failfast = True
+ suite = unittest.makeSuite(Foo)
+ suite.run(result)
+
+ expected = ['a1', 'a2', 'b1']
+ self.assertEqual(events, expected)
+
 # "This class attribute gives the exception raised by the test() method.
 # If a test framework needs to use a specialized exception, possibly to
 # carry additional information, it must subclass this exception in
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -191,6 +191,9 @@
 Library
 -------
 
+- Issue #22894: TestCase.subTest() would cause the test suite to be stopped
+ when in failfast mode, even in the absence of failures.
+
 - Issue #22796: HTTP cookie parsing is now stricter, in order to protect
 against potential injection attacks.
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /