# Behavior traces — pytest-dev/pytest

> Canonical page: https://codevetter.com/unpack/pytest/behavior-traces

# Behavior traces — pytest-dev/pytest

Scanned commit 2887015cade4757385308e7a7d8083557fc637e2 (2026-09-29). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Three principal flows were followed end-to-end: startup into session dispatch, Python test collection and execution, and failure-history persistence into a later selection. Additional branches show assertion-cache loading, fixture teardown, XML output, and stepwise interruption. These traces describe default implementations; hook replacements and wrappers can change behavior. Error and worker conditions are retained where they affect execution order.
- Startup proceeds __main__ → _console_main → config._main → _prepareconfig → get_config → pytest_cmdline_parse; a version-only fast path returns before full infrastructure startup. — [src/pytest/__main__.py#L5-L9](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/pytest/__main__.py#L5-L9) [src/_pytest/config/__init__.py#L238-L251](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/config/__init__.py#L238-L251) [src/_pytest/config/__init__.py#L277-L286](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/config/__init__.py#L277-L286) [src/_pytest/config/__init__.py#L432-L443](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/config/__init__.py#L432-L443)
- Config.parse discovers settings → checks version → installs assertion rewriting → adjusts pythonpath → loads explicit plugins → optionally loads pytest11 entry points → loads PYTEST_PLUGINS → loads initial conftests. — [src/_pytest/config/__init__.py#L1651-L1681](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/config/__init__.py#L1651-L1681) [src/_pytest/config/__init__.py#L1692-L1739](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/config/__init__.py#L1692-L1739)
- config._main dispatches pytest_cmdline_main → main.py wrap_session → configure → sessionstart → collection → runtestloop; finally it restores cwd, calls sessionfinish if startup completed, and unconfigures. — [src/_pytest/config/__init__.py#L259-L266](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/config/__init__.py#L259-L266) [src/_pytest/main.py#L324-L333](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/main.py#L324-L333) [src/_pytest/main.py#L362-L397](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/main.py#L362-L397)
- Python collection follows pytest_collect_file → pytest_pycollect_makemodule → Module importtestmodule/import_path → Module.collect/parsefactories → _genfunctions → pytest_generate_tests → Function creation. — [src/_pytest/python.py#L215-L236](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/python.py#L215-L236) [src/_pytest/python.py#L471-L518](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/python.py#L471-L518) [src/_pytest/python.py#L521-L533](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/python.py#L521-L533) [src/_pytest/python.py#L573-L587](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/python.py#L573-L587)
- A test executes pytest_runtest_protocol → runtestprotocol → setup report → call report only after successful setup → teardown report; Function.setup fills fixtures and Function.runtest dispatches pytest_pyfunc_call. — [src/_pytest/runner.py#L115-L151](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/runner.py#L115-L151) [src/_pytest/python.py#L1796-L1801](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/python.py#L1796-L1801) [src/_pytest/fixtures.py#L864-L868](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/fixtures.py#L864-L868) [src/_pytest/python.py#L181-L198](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/python.py#L181-L198)
- Fixture execution resolves dependencies before checking cached results → finishes a mismatched parameter instance → registers dependency finalizers → calls pytest_fixture_setup → call_fixture_func; yield teardown advances the generator once more and rejects an additional yield. — [src/_pytest/fixtures.py#L1231-L1297](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/fixtures.py#L1231-L1297) [src/_pytest/fixtures.py#L1375-L1407](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/fixtures.py#L1375-L1407) [src/_pytest/fixtures.py#L1051-L1084](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/fixtures.py#L1051-L1084)
- Failure persistence proceeds pytest_configure → Cache.for_config → LFPlugin cached-history load → report updates → sessionfinish changed-history write; a subsequent --lf run selects known failed items, while --ff places them first and workers skip saving history. — [src/_pytest/cacheprovider.py#L564-L574](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/cacheprovider.py#L564-L574) [src/_pytest/cacheprovider.py#L327-L335](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/cacheprovider.py#L327-L335) [src/_pytest/cacheprovider.py#L362-L408](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/cacheprovider.py#L362-L408) [src/_pytest/cacheprovider.py#L430-L439](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/cacheprovider.py#L430-L439)
- Assertion imports call exec_module → _read_pyc →, on a miss, _rewrite_test and optional _write_pyc → exec; stepwise failure reports separately set Session.shouldstop and persist continuation state at sessionfinish outside workers. — [src/_pytest/assertion/rewrite.py#L147-L187](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/assertion/rewrite.py#L147-L187) [src/_pytest/assertion/rewrite.py#L314-L344](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/assertion/rewrite.py#L314-L344) [src/_pytest/stepwise.py#L176-L218](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/stepwise.py#L176-L218) [src/_pytest/main.py#L409-L415](https://github.com/pytest-dev/pytest/blob/2887015cade4757385308e7a7d8083557fc637e2/src/_pytest/main.py#L409-L415)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
