mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
This commit is contained in:
parent
4505f65ae7
commit
da2bf9f66d
3 changed files with 17 additions and 1 deletions
|
@ -514,7 +514,7 @@ class TestCase(object):
|
||||||
case as failed but resumes execution at the end of the enclosed
|
case as failed but resumes execution at the end of the enclosed
|
||||||
block, allowing further test code to be executed.
|
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
|
yield
|
||||||
return
|
return
|
||||||
parent = self._subtest
|
parent = self._subtest
|
||||||
|
|
|
@ -425,6 +425,20 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
|
||||||
expected = ['a1', 'a2', 'b1']
|
expected = ['a1', 'a2', 'b1']
|
||||||
self.assertEqual(events, expected)
|
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.
|
# "This class attribute gives the exception raised by the test() method.
|
||||||
# If a test framework needs to use a specialized exception, possibly to
|
# If a test framework needs to use a specialized exception, possibly to
|
||||||
# carry additional information, it must subclass this exception in
|
# carry additional information, it must subclass this exception in
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fixed :meth:`unittest.TestCase.debug` when used to call test methods with
|
||||||
|
subtests. Patch by Bruno Oliveira.
|
Loading…
Add table
Add a link
Reference in a new issue