Message348708
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. |
|
| Date |
User |
Action |
Args |
| 2019-07-30 00:57:04 | Matthew Roeschke | set | recipients:
+ Matthew Roeschke |
| 2019-07-30 00:57:04 | Matthew Roeschke | set | messageid: <1564448224.13.0.206274970387.issue37712@roundup.psfhosted.org> |
| 2019-07-30 00:57:04 | Matthew Roeschke | link | issue37712 messages |
| 2019-07-30 00:57:03 | Matthew Roeschke | create | |
|