Open
Description
A demo for an infinite recursion:
# test_func.py
from unittest import mock
depth = 0
def func(obj):
global depth
depth = depth + 1
print(depth)
if depth == 1000:
raise Exception
return func(obj.attr) # Infinite loop
def test_func():
func(mock.MagicMock())
test_func()
$ python test_func.py
...
983
984
985
Traceback (most recent call last):
File "test_func.py", line 20, in <module>
test_func()
...
if type(value) is cls:
RecursionError: maximum recursion depth exceeded while calling a Python object
But pytest
just hangs:
$ pytest test_func.py --capture no
...
940
941
942
This happens on both Linux and Windows.
> pytest -V
pytest 6.2.2