Skip to content

Commit da2bf9f

Browse files
nicoddemusberkerpeksag
authored andcommitted
bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
1 parent 4505f65 commit da2bf9f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Lib/unittest/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def subTest(self, msg=_subtest_msg_sentinel, **params):
514514
case as failed but resumes execution at the end of the enclosed
515515
block, allowing further test code to be executed.
516516
"""
517-
if not self._outcome.result_supports_subtests:
517+
if self._outcome is None or not self._outcome.result_supports_subtests:
518518
yield
519519
return
520520
parent = self._subtest

Lib/unittest/test/test_case.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ def test_c(self):
425425
expected = ['a1', 'a2', 'b1']
426426
self.assertEqual(events, expected)
427427

428+
def test_subtests_debug(self):
429+
# Test debug() with a test that uses subTest() (bpo-34900)
430+
events = []
431+
432+
class Foo(unittest.TestCase):
433+
def test_a(self):
434+
events.append('test case')
435+
with self.subTest():
436+
events.append('subtest 1')
437+
438+
Foo('test_a').debug()
439+
440+
self.assertEqual(events, ['test case', 'subtest 1'])
441+
428442
# "This class attribute gives the exception raised by the test() method.
429443
# If a test framework needs to use a specialized exception, possibly to
430444
# carry additional information, it must subclass this exception in
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed :meth:`unittest.TestCase.debug` when used to call test methods with
2+
subtests. Patch by Bruno Oliveira.

0 commit comments

Comments
 (0)