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

Session and modules fixtures spans should not be part of test spans #40

Open
sk- opened this issue Feb 24, 2025 · 0 comments
Open

Session and modules fixtures spans should not be part of test spans #40

sk- opened this issue Feb 24, 2025 · 0 comments

Comments

@sk-
Copy link

sk- commented Feb 24, 2025

Session and modules fixtures are included within a test span, making some tests longer than they really are.

Setup of session fixtures are included in the first test, while the teardown is part of the last. An example can be seen with the following code:

import time
from collections.abc import Iterator

import pytest


@pytest.fixture(scope="session", autouse=True)
def session_fixture() -> Iterator[None]:
    time.sleep(2)
    yield
    time.sleep(2)


@pytest.fixture(scope="module", autouse=True)
def module_fixture() -> Iterator[None]:
    time.sleep(1)
    yield
    time.sleep(1)


@pytest.fixture
def function_fixture() -> Iterator[None]:
    time.sleep(0.5)
    yield
    time.sleep(0.5)


@pytest.mark.parametrize("header", ["without bearer", "bearer ", "bearer not_found"])
def test_parametrized(header: str, function_fixture: None) -> None:
    assert header
    time.sleep(1)

In the image below it can be seen how the first and third test take 3 seconds longer than the second one and that's only because the time spend in the session/module setup/teardown.
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant