CodeVetter · Repo Unpack · Behavior traces
pytest-dev/pytest
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.
- 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.
- 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.
- Python collection follows pytest_collect_file → pytest_pycollect_makemodule → Module importtestmodule/import_path → Module.collect/parsefactories → _genfunctions → pytest_generate_tests → Function creation.
- 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.
- 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.
- 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.
- 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.