Skip to content

pytest hangs when RecursionError happens for MagicMock #8482

Open
@jiasli

Description

@jiasli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: tracebacksrelated to displaying and handling of tracebackstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions