summaryrefslogtreecommitdiff
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-11-23 15:55:11 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2014-11-23 15:55:11 +0100
commit18f22989dd73c7b9c09a746e89cb9d7ce7243d1d (patch)
tree88e0aaf2130047e6e6f85f823bf313a4b4fa1a8e /Lib/unittest/test
parenta21de3d45ec2aebf899712cbd0e44eba9611d2af (diff)
downloadcpython-git-18f22989dd73c7b9c09a746e89cb9d7ce7243d1d.tar.gz
Issue #22894: TestCase.subTest() would cause the test suite to be stopped when in failfast mode, even in the absence of failures.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/test_case.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index f0b327dd82..c7ff3b0e3c 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -397,6 +397,34 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
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