This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Matthew Roeschke
Recipients Matthew Roeschke
Date 2019-07-30.00:57:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1564448224.13.0.206274970387.issue37712@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-07-30 00:57:04Matthew Roeschkesetrecipients: + Matthew Roeschke
2019-07-30 00:57:04Matthew Roeschkesetmessageid: <1564448224.13.0.206274970387.issue37712@roundup.psfhosted.org>
2019-07-30 00:57:04Matthew Roeschkelinkissue37712 messages
2019-07-30 00:57:03Matthew Roeschkecreate