Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest subTests() fails when called from debug() #79081

Closed
nicoddemus mannequin opened this issue Oct 4, 2018 · 8 comments
Closed

unittest subTests() fails when called from debug() #79081

nicoddemus mannequin opened this issue Oct 4, 2018 · 8 comments
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@nicoddemus
Copy link
Mannequin

nicoddemus mannequin commented Oct 4, 2018

BPO 34900
Nosy @berkerpeksag, @nicoddemus, @tirkarthi
PRs
  • bpo-34900: Fix subTests to not crash when called from TestCase.debug() #9707
  • [3.7] bpo-34900: Make TestCase.debug() work with subtests (GH-9707) #9818
  • [3.6] bpo-34900: Make TestCase.debug() work with subtests (GH-9707) #9819
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-10-12.11:09:21.672>
    created_at = <Date 2018-10-04.22:24:33.818>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'unittest subTests() fails when called from debug()'
    updated_at = <Date 2018-10-12.11:09:21.672>
    user = 'https://github.com/nicoddemus'

    bugs.python.org fields:

    activity = <Date 2018-10-12.11:09:21.672>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-10-12.11:09:21.672>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2018-10-04.22:24:33.818>
    creator = 'Bruno Oliveira'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34900
    keywords = ['patch']
    message_count = 8.0
    messages = ['327092', '327115', '327117', '327121', '327123', '327577', '327579', '327580']
    nosy_count = 3.0
    nosy_names = ['berker.peksag', 'Bruno Oliveira', 'xtreak']
    pr_nums = ['9707', '9818', '9819']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34900'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @nicoddemus
    Copy link
    Mannequin Author

    nicoddemus mannequin commented Oct 4, 2018

    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().

    @nicoddemus nicoddemus mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 4, 2018
    @berkerpeksag
    Copy link
    Member

    PR 9707 looks good to me. I will merge it once your CLA is processed by the PSF staff. Thanks!

    @berkerpeksag berkerpeksag added 3.8 (EOL) end of life type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 5, 2018
    @nicoddemus
    Copy link
    Mannequin Author

    nicoddemus mannequin commented Oct 5, 2018

    Great, thanks again for the quick review.

    @berkerpeksag
    Copy link
    Member

    FYI, I just noticed that this is a duplicate of bpo-29551, but decided to keep this one open.

    @nicoddemus
    Copy link
    Mannequin Author

    nicoddemus mannequin commented Oct 5, 2018

    FYI, I just noticed that this is a duplicate of bpo-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.

    @berkerpeksag
    Copy link
    Member

    New changeset da2bf9f by Berker Peksag (Bruno Oliveira) in branch 'master':
    bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
    da2bf9f

    @berkerpeksag
    Copy link
    Member

    New changeset 7a98e30 by Berker Peksag (Miss Islington (bot)) in branch '3.7':
    bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
    7a98e30

    @berkerpeksag
    Copy link
    Member

    New changeset c1fe49c by Berker Peksag (Miss Islington (bot)) in branch '3.6':
    bpo-34900: Make TestCase.debug() work with subtests (GH-9707)
    c1fe49c

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant