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

Exception frames from unittest.TestCase.fail dependent on nesting #81893

Closed
MatthewRoeschke mannequin opened this issue Jul 30, 2019 · 3 comments
Closed

Exception frames from unittest.TestCase.fail dependent on nesting #81893

MatthewRoeschke mannequin opened this issue Jul 30, 2019 · 3 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@MatthewRoeschke
Copy link
Mannequin

MatthewRoeschke mannequin commented Jul 30, 2019

BPO 37712
Nosy @rbtcollins, @ezio-melotti, @voidspace, @cjerdonek, @iritkatriel
Superseder
  • bpo-24959: unittest swallows part of stack trace when raising AssertionError in a TestCase
  • 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 2021-04-09.13:26:49.147>
    created_at = <Date 2019-07-30.00:57:04.109>
    labels = ['3.7', 'type-bug', 'library']
    title = 'Exception frames from unittest.TestCase.fail dependent on nesting'
    updated_at = <Date 2021-04-09.13:26:49.147>
    user = 'https://bugs.python.org/MatthewRoeschke'

    bugs.python.org fields:

    activity = <Date 2021-04-09.13:26:49.147>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-09.13:26:49.147>
    closer = 'iritkatriel'
    components = ['Library (Lib)']
    creation = <Date 2019-07-30.00:57:04.109>
    creator = 'Matthew Roeschke'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37712
    keywords = []
    message_count = 3.0
    messages = ['348708', '390488', '390617']
    nosy_count = 6.0
    nosy_names = ['rbcollins', 'ezio.melotti', 'michael.foord', 'chris.jerdonek', 'Matthew Roeschke', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '24959'
    type = 'behavior'
    url = 'https://bugs.python.org/issue37712'
    versions = ['Python 3.7']

    @MatthewRoeschke
    Copy link
    Mannequin Author

    MatthewRoeschke mannequin commented Jul 30, 2019

    With this toy example:

    import unittest
    
    def this_fails():
        a = 1 + None
    
    class TestExample(unittest.TestCase):
    
        def test_this(self):
            try:
                this_fails()
            except Exception:
                self.fail('Fail')
    
    if __name__ == '__main__':
        unittest.run()

    I get the last frame for each chained exception:

    Traceback (most recent call last):
      File "/Users/me/test.py", line 10, in test_this
        this_fails()
    TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/me/test.py", line 12, in test_this
        self.fail('Fail')
    AssertionError: Fail

    But if the toy example contained a nested call, e.g.

        def helper(self):
            try:
                this_fails()
            except Exception:
                self.fail('Fail')
    
        def test_this(self):
            self.helper() 

    I get the last 2 frames for each chained exception:

    Traceback (most recent call last):
      File "/Users/me/test.py", line 10, in helper
        this_fails()
      File "/Users/me/test.py", line 4, in this_fails
        a = 1 + None
    TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/me/test.py", line 15, in test_this
        self.helper()
      File "/Users/me/test.py", line 12, in helper
        self.fail('Fail')
    AssertionError: Fail

    Ideally, it would be great if the traceback went back to the root of the exception regardless.

    @MatthewRoeschke MatthewRoeschke mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 30, 2019
    @iritkatriel
    Copy link
    Member

    I think this is the same as bpo-42247.

    @cjerdonek
    Copy link
    Member

    I think this is the same as bpo-37712.

    This issue was first reported as bpo-24959. It would be better to close the newer issues as duplicates of the first one, instead of keeping all the duplicates open. Otherwise, the history and discussion gets fragmented across multiple locations.

    @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 stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants