classification
Title: unittest subTests() fails when called from debug()
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Bruno Oliveira, berker.peksag, xtreak
Priority: normal Keywords: patch

Created on 2018-10-04 22:24 by Bruno Oliveira, last changed 2018-10-12 11:09 by berker.peksag. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9707 merged python-dev, 2018-10-04 23:27
PR 9818 merged miss-islington, 2018-10-12 10:36
PR 9819 merged miss-islington, 2018-10-12 10:36
Messages (8)
msg327092 - (view) Author: Bruno Oliveira (Bruno Oliveira) * Date: 2018-10-04 22:24
Consider this code:

    import unittest


    class TC(unittest.TestCase):

        def test_subtest(self):
            with self.subTest():
                pass


    tc = TC('test_subtest')
    tc.run()

This works when executed, but if we change ``tc.run()`` to ``tc.debug()`` we get the following exception:    

    Traceback (most recent call last):
      File ".tmp\test-unittest-regression.py", line 13, in <module>
        tc.debug()
      File "C:\Users\Bruno\AppData\Local\Programs\Python\Python36\lib\unittest\case.py", line 658, in debug
        getattr(self, self._testMethodName)()
      File ".tmp\test-unittest-regression.py", line 7, in test_subtest
        with self.subTest():
      File "C:\Users\Bruno\AppData\Local\Programs\Python\Python36\lib\contextlib.py", line 81, in __enter__
        return next(self.gen)
      File "C:\Users\Bruno\AppData\Local\Programs\Python\Python36\lib\unittest\case.py", line 512, in subTest
        if not self._outcome.result_supports_subtests:
    AttributeError: 'NoneType' object has no attribute 'result_supports_subtests'    

Looking at the code, ``subTest`` assumes that the ``TestCase`` instance has the ``self._outcome`` atribute, which is set only by ``run()``.
msg327115 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-10-05 09:30
PR 9707 looks good to me. I will merge it once your CLA is processed by the PSF staff. Thanks!
msg327117 - (view) Author: Bruno Oliveira (Bruno Oliveira) * Date: 2018-10-05 09:52
Great, thanks again for the quick review.
msg327121 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-10-05 10:27
FYI, I just noticed that this is a duplicate of issue 29551, but decided to keep this one open.
msg327123 - (view) Author: Bruno Oliveira (Bruno Oliveira) * Date: 2018-10-05 10:34
> FYI, I just noticed that this is a duplicate of issue 29551, but decided to keep this one open.

OK thanks. I did try to search for open issues before filing this one by using the "subtest result_supports_subtests" terms, as I figured a bug report would include the traceback, that's why I didn't find 29551, heh.
msg327577 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-10-12 10:36
New changeset da2bf9f66d0c95b988c5d87646d168f65499b316 by Berker Peksag (Bruno Oliveira) in branch 'master':
bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
https://github.com/python/cpython/commit/da2bf9f66d0c95b988c5d87646d168f65499b316
msg327579 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-10-12 11:07
New changeset 7a98e302c37781f9c6448a28bc70bff18b7e2862 by Berker Peksag (Miss Islington (bot)) in branch '3.7':
bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
https://github.com/python/cpython/commit/7a98e302c37781f9c6448a28bc70bff18b7e2862
msg327580 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-10-12 11:07
New changeset c1fe49c01f3850aaa32a7d75e47f90eb5c5f7efe by Berker Peksag (Miss Islington (bot)) in branch '3.6':
bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
https://github.com/python/cpython/commit/c1fe49c01f3850aaa32a7d75e47f90eb5c5f7efe
History
Date User Action Args
2019-04-08 16:39:55xtreaklinkissue36554 superseder
2018-10-12 11:09:21berker.peksagsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-12 11:07:48berker.peksagsetmessages: + msg327580
2018-10-12 11:07:06berker.peksagsetmessages: + msg327579
2018-10-12 10:36:15miss-islingtonsetpull_requests: + pull_request9197
2018-10-12 10:36:09miss-islingtonsetpull_requests: + pull_request9196
2018-10-12 10:36:07berker.peksagsetmessages: + msg327577
2018-10-05 10:34:35Bruno Oliveirasetmessages: + msg327123
2018-10-05 10:29:40berker.peksaglinkissue29551 superseder
2018-10-05 10:27:41berker.peksagsetmessages: + msg327121
2018-10-05 09:52:35Bruno Oliveirasetmessages: + msg327117
2018-10-05 09:30:58berker.peksagsetversions: + Python 3.8, - Python 3.4, Python 3.5
nosy: + berker.peksag

messages: + msg327115

type: crash -> behavior
2018-10-05 03:13:31xtreaksetnosy: + xtreak
2018-10-04 23:27:13python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request9092
2018-10-04 22:25:02Bruno Oliveirasettype: crash
2018-10-04 22:24:33Bruno Oliveiracreate