Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teardown duration reported in the following setup (pytest_runtest_logreport) #5591

Open
Sup3rGeo opened this issue Jul 10, 2019 · 3 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed type: refactoring internal improvements to the code

Comments

@Sup3rGeo
Copy link
Member

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.

@nicoddemus
Copy link
Member

Hi @Sup3rGeo!

This is a side-effect of #4871, I'm afraid: fixtures are teardown during setup (when it is decided that a different fixture instance is needed).

I don't think there's a simple solution other than a full refactoring of the teardown mechanism, as discussed in #4871. 😕

@nicoddemus nicoddemus added the type: question general question, might be closed after 2 weeks of inactivity label Jul 11, 2019
@Sup3rGeo
Copy link
Member Author

I see. You tagged this issue as a question, in that case this could be closed.

Or maybe this is indeed a bug and should we tag it as such and leave it opened?

@nicoddemus
Copy link
Member

Let's leave it open then; it is linked with #4871, so eventually we can announce it has been solved in the changelog together. 👍

@nicoddemus nicoddemus added topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed type: refactoring internal improvements to the code and removed type: question general question, might be closed after 2 weeks of inactivity labels Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed type: refactoring internal improvements to the code
Projects
None yet
Development

No branches or pull requests

2 participants