Skip to content

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

@sk-

Description

@sk-

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions