[issue37712] Exception frames from unittest.TestCase.fail dependent on nesting
Matthew Roeschke
report at bugs.python.org
Mon Jul 29 20:57:04 EDT 2019
New submission from Matthew Roeschke <mroeschke at housecanary.com>:
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.
----------
components: Library (Lib)
messages: 348708
nosy: Matthew Roeschke
priority: normal
severity: normal
status: open
title: Exception frames from unittest.TestCase.fail dependent on nesting
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37712>
_______________________________________
More information about the Python-bugs-list
mailing list