Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/unittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def subTest(self, msg=_subtest_msg_sentinel, **params):
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
Expand Down
14 changes: 14 additions & 0 deletions Lib/unittest/test/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ def test_c(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed :meth:`unittest.TestCase.debug` when used to call test methods with

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

subtests. Patch by Bruno Oliveira.