Skip to content

livery.extensions.pytest._contexts

livery.extensions.pytest._contexts

Name each test's coverage context in a metered pytest run.

Registered through livery-extensions-pytest's pytest11 entry point, so every pytest this venv starts carries it. It acts only when coverage's process startup is measuring the process (inside a CI check leg the test runner arms COVERAGE_PROCESS_START in pytest's environment while coverage is listed, and in the gate's own never): each test records under one context, its node id, from its setup to its teardown, so a leg can split one pooled run's data by the suite each test belongs to. Outside a metered run every hook returns at once, and a meter that is not collecting is left alone.

Under coverage's sysmon core a line is recorded under the first context that reaches it and never again, so a suite's contexts hold the lines its tests reached first. The leg's split keeps the union complete regardless: a line another suite's test reached first is stored with that suite, whose closure holds the file.

Functions:

Name Description
pytest_runtest_setup

Record the test under its node id, from its setup to its teardown.

pytest_runtest_logfinish

Return to the empty context once the test is over.

Attributes:

Name Type Description
ARMED

ARMED module-attribute

ARMED = 'COVERAGE_PROCESS_START'

pytest_runtest_setup

pytest_runtest_setup(item: Item) -> None

Record the test under its node id, from its setup to its teardown.

Switched in the process that runs the test, at its setup: the hooks that report on a test also run in the process that schedules the tests, whose own lines belong to no test.

Source code in packages/extensions/pytest/src/livery/extensions/pytest/_contexts.py
def pytest_runtest_setup(item: pytest.Item) -> None:
    """Record the test under its node id, from its setup to its teardown.

    Switched in the process that runs the test, at its setup: the hooks
    that report on a test also run in the process that schedules the
    tests, whose own lines belong to no test.
    """
    _switch(item.nodeid)

pytest_runtest_logfinish

pytest_runtest_logfinish(nodeid: str, location: object) -> None

Return to the empty context once the test is over.

Source code in packages/extensions/pytest/src/livery/extensions/pytest/_contexts.py
def pytest_runtest_logfinish(nodeid: str, location: object) -> None:
    """Return to the empty context once the test is over."""
    _switch("")