pytest-dev / pytest-dev/pytest

Teardown duration reported in the following setup (pytest_runtest_logreport)

Open
#5,591 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: fixtures type: bug type: refactoring
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.