pytest-dev / pytest-dev/pytest
--durations is tricked by freezegun
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
--durations is tricked by freezegun, when freezegun is used in autouse fixture.
Example:
from freezegun import freeze_time
@pytest.yield_fixture(autouse=True)
def frozen_time():
with freeze_time("2020-01-01T12:00:00Z"):
yield
def test_my_django_view(admin_client):
resp = admin_client.get(...)
assert resp.status_code == 200
...
Command:
pytest --reuse-db -s -vv --durations=5
Result:
============================================= slowest 5 durations =============================================
1609479015.03s setup test_my_django_view1
1609479014.85s setup test_my_django_view2
1609479014.70s setup test_my_django_view3
1609479014.60s setup test_my_django_view4
1609479014.47s setup test_my_django_view5
Versions (Python 3.10.2):
pytest 7.1.2
pytest-django 4.2.0
freezegun 1.2.2
freezegun is latest version which has some work done regarding this: https://github.com/spulec/freezegun/pull/460
If every test function is decorated individually - then everything works as expected:
from freezegun import freeze_time
@freeze_time("2020-01-01T12:00:00Z")
def test_my_django_view(admin_client):
resp = admin_client.get(...)
assert resp.status_code == 200
...
Report:
3.75s setup test_my_django_view1
0.49s call test_my_django_view2
0.28s call test_my_django_view3
0.27s call test_my_django_view4
0.25s call test_my_django_view5
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 with freezegun devs) - it's fine
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with an autouse freezegun fixture and pytest --durations=5, comparing it with a test-level decorator. Start by tracing pytest's duration reporting and setup timing; done means the command no longer reports frozen epoch timestamps as test durations, while real slow tests remain visible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100