Repository navigation
Closed
Labels
topic: tracebacksrelated to displaying and handling of tracebackstype: bugproblem that needs to be addressed
Description
When running a test that raises an Exception with a loop in the __causes__ variable (by using raise A from B), pytest hangs forever but a normal execution succeeds.
This is a minimal example I have created to reproduce this issue:
class SomethingWentWrong(Exception):
pass
def run_safely(callable):
"""
Runs the callable and returns it,
or raises SomethingWentWrong if there is any exception
"""
try:
return callable()
except Exception as e:
raise SomethingWentWrong() from e
def do_error():
return 0 / 0
def do_something():
try:
return run_safely(lambda: do_error())
except SomethingWentWrong as exc:
raise exc.__cause__
if __name__ == "__main__":
do_something()
def test_bug():
do_something()Note inside the except clause in do_something() it is reraising the original clause of the exception, and my guess is that implicitly it is creating a loop there.
A normal execution runs fine and shows the chained exception:
$ python test_bug.py
Traceback (most recent call last):
File "test_bug.py", line 22, in do_something
return run_safely(lambda: do_error())
File "test_bug.py", line 13, in run_safely
raise SomethingWentWrong() from e
__main__.SomethingWentWrong
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_bug.py", line 30, in <module>
do_something()
File "test_bug.py", line 26, in do_something
raise exc.__cause__
File "test_bug.py", line 11, in run_safely
return callable()
File "test_bug.py", line 22, in <lambda>
return run_safely(lambda: do_error())
File "test_bug.py", line 17, in do_error
return 0 / 0
ZeroDivisionError: division by zero
But when running with pytest it just hangs forever:
$ pytest test_bug.py
=============================================================================== test session starts ===============================================================================
platform darwin -- Python 3.6.6, pytest-3.7.1, py-1.5.4, pluggy-0.7.1
rootdir: /Users/nova/workspace/sherlock, inifile:
collected 1 item
test_bug.py
Version information:
$ python -V
Python 3.6.6
$ pip list
Package Version
-------------- -------
atomicwrites 1.1.5
attrs 18.1.0
more-itertools 4.3.0
pip 18.0
pluggy 0.7.1
py 1.5.4
pytest 3.7.1
setuptools 40.0.0
six 1.11.0
$ uname -a
Darwin 10.0.0.10 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64
Metadata
Metadata
Assignees
Labels
topic: tracebacksrelated to displaying and handling of tracebackstype: bugproblem that needs to be addressed
Activity
asottile commentedon Aug 11, 2018
confirmed, goes away with
--tb=nativeHere's an interrupted run with
--fulltrace:asottile commentedon Aug 11, 2018
This one seemed fun, my fix is in #3805
jcugat commentedon Aug 11, 2018
The funniest thing was creating the minimal reproducible example, since the original issue appeared at work and was spread between 3 different libraries. At the beginning I wasn't even sure it was a pytest bug.
Thanks for taking a loot at it @asottile!
Update pytest to 3.7.2 (#1755)
Update pytest to 3.7.2 (#25)
Update pytest to 3.7.2 (#8)
Merge #28
Scheduled monthly dependency update for October (#389)
shakori999 commentedon Jan 1, 2022
sorry guys but i still didn't know how to solve it? it still runs forever? should I open a new issue?
asottile commentedon Jan 1, 2022
yes, this is a 3 year old issue with a different root cause -- please make a new issue with details on how to reproduce the problem