Open trimailov opened 1 year ago
https://github.com/spulec/freezegun/issues/433 is a related issue that is already solved but does not solve this one.
Here is a related comment: https://github.com/spulec/freezegun/issues/176#issuecomment-1149163454 that states the same problem and https://github.com/spulec/freezegun/issues/176#issuecomment-1149171726 that mentions pytest-durations.
Reading the source code of pytest-freezegun
I figured out how it avoids tricking pytest timings:
https://github.com/ktosiek/pytest-freezegun/blob/master/pytest_freezegun.py#L39-L41
So the solution is to call freeze_time
with the ignore argument:
freeze_time("2020-01-01T12:00:00Z", ignore=['_pytest.runner', '_pytest.terminal'])
These should probably be added to the default ignore list.
According to the docs, the default ignore list includes ['_pytest.terminal.', '_pytest.runner.']
.
Probably, the dots at the end break it.
I tried forking and adding them to DEFAULT_IGNORE_LIST
but this breaks the tests: RecursionError: maximum recursion depth exceeded
.
This is a copy of an issue in
pytest
, that needs coordination withfreezegun
.--durations
is tricked byfreezegun
, whenfreezegun
is used inautouse
fixture.Example:
Command:
Result:
Versions (
Python 3.10.2
):freezegun
is latest version which has some work done regarding this: https://github.com/spulec/freezegun/pull/460If every test function is decorated individually - then everything works as expected:
Report:
Related issue: https://github.com/pytest-dev/pytest/issues/7764
Like in the linked issue - if you say that it's my problem of (mis)using
freezegun
(or that I need to speak withfreezegun
devs) - it's fine