pytest-dev / pytest-dev/pytest
Teardown duration reported in the following setup (pytest_runtest_logreport)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
This simple test:
import time
import pytest
@pytest.fixture(scope="module", params=[1, 2])
def fix():
time.sleep(2)
yield
time.sleep(2)
@pytest.mark.parametrize('par', [1, 2])
def test_one(fix, par):
pass
And this conftest.py file:
def pytest_runtest_logreport(report):
print(f"Report at {report.when}, with duration {report.duration}")
The prints I get are:
Report at setup, with duration 2.00620698928833
Report at call, with duration 0.0
Report at teardown, with duration 0.0
Report at setup, with duration 0.0
Report at call, with duration 0.0
Report at teardown, with duration 0.0
Report at setup, with duration 4.012362957000732
Report at call, with duration 0.0
Report at teardown, with duration 0.0
Report at setup, with duration 0.0
Report at call, with duration 0.0
Report at teardown, with duration 2.0061838626861572
So, basically, instead of having in the middle of test a teardown with 2 seconds and then a setup with 2 seconds, I have instead a setup of 4 seconds.
Is it normal or a bug?
Windows 10 and python 3.6 venv with only pytest 5.0.1 installed.
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 example using the shown test and conftest.py, then inspect the pytest_runtest_logreport output for setup and teardown timing. Trace fixture setup and teardown across the parametrized tests to determine whether the durations are reported correctly. Done when the behavior is confirmed as expected or a focused fix and regression test are identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100