From eddd087e23354805ea2f6fededd8e5b40a355295 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 4 Oct 2018 20:19:40 -0300 Subject: [PATCH 1/2] Fix TestCase.debug() when used to call test methods with subtests Fixes bpo-34900 --- Lib/unittest/case.py | 2 +- Lib/unittest/test/test_case.py | 14 ++++++++++++++ .../2018-10-05-05-55-53.bpo-34900.8RNiFu.rst | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 1faa6b641f2d755..2579c30474b5366 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -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 diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index baabddd06f41a41..687fe5b65f109e7 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -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 diff --git a/Misc/NEWS.d/next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst b/Misc/NEWS.d/next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst new file mode 100644 index 000000000000000..df86ca5ad053141 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst @@ -0,0 +1,2 @@ +Fixed ``TestCase.debug()`` when used to call test methods with subtests. +Patch by Bruno Oliveira. From bb8a047cb834b3b3c13a6f6ebeba6203ba09330d Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Fri, 5 Oct 2018 12:28:23 +0300 Subject: [PATCH 2/2] markup --- .../next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst b/Misc/NEWS.d/next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst index df86ca5ad053141..20e3a0e2d5a19b6 100644 --- a/Misc/NEWS.d/next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst +++ b/Misc/NEWS.d/next/Library/2018-10-05-05-55-53.bpo-34900.8RNiFu.rst @@ -1,2 +1,2 @@ -Fixed ``TestCase.debug()`` when used to call test methods with subtests. -Patch by Bruno Oliveira. +Fixed :meth:`unittest.TestCase.debug` when used to call test methods with +subtests. Patch by Bruno Oliveira.