summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2018-10-12 10:35:55 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2018-10-12 10:35:55 (GMT)
commitda2bf9f66d0c95b988c5d87646d168f65499b316 (patch)
tree3373f35a7c27fa838b9c555891d8814f4358da04 /Lib/unittest
parent4505f65ae7807f2420ed14d4f060e7cd5c4039d3 (diff)
downloadcpython-da2bf9f66d0c95b988c5d87646d168f65499b316.zip
cpython-da2bf9f66d0c95b988c5d87646d168f65499b316.tar.gz
cpython-da2bf9f66d0c95b988c5d87646d168f65499b316.tar.bz2
bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py2
-rw-r--r--Lib/unittest/test/test_case.py14
2 files changed, 15 insertions, 1 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 1faa6b6..2579c30 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -514,7 +514,7 @@ class TestCase(object):
case as failed but resumes execution at the end of the enclosed
block, allowing further test code to be executed.
"""
- if not self._outcome.result_supports_subtests:
+ if self._outcome is None or not self._outcome.result_supports_subtests:
yield
return
parent = self._subtest
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index baabddd..687fe5b 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -425,6 +425,20 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
expected = ['a1', 'a2', 'b1']
self.assertEqual(events, expected)
+ def test_subtests_debug(self):
+ # Test debug() with a test that uses subTest() (bpo-34900)
+ events = []
+
+ class Foo(unittest.TestCase):
+ def test_a(self):
+ events.append('test case')
+ with self.subTest():
+ events.append('subtest 1')
+
+ Foo('test_a').debug()
+
+ self.assertEqual(events, ['test case', 'subtest 1'])
+
# "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