pytest-impacted 0.35.0__tar.gz → 0.37.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. pytest_impacted-0.37.0/.github/dependabot.yml +35 -0
  2. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.github/workflows/ci-impacted.yml +4 -4
  3. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.github/workflows/ci.yml +13 -4
  4. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.pre-commit-config.yaml +1 -1
  5. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/CLAUDE.md +65 -4
  6. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/PKG-INFO +12 -7
  7. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/README.md +10 -6
  8. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/docs/extensions.md +4 -1
  9. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/docs/usage.md +63 -11
  10. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pyproject.toml +3 -0
  11. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/api.py +11 -1
  12. pytest_impacted-0.37.0/pytest_impacted/cli.py +314 -0
  13. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/extensions.py +17 -4
  14. pytest_impacted-0.37.0/pytest_impacted/file_map.py +119 -0
  15. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/git.py +31 -0
  16. pytest_impacted-0.37.0/pytest_impacted/ini.py +230 -0
  17. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/plugin.py +287 -34
  18. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/strategies.py +8 -2
  19. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted.egg-info/PKG-INFO +12 -7
  20. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted.egg-info/SOURCES.txt +7 -0
  21. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted.egg-info/requires.txt +1 -0
  22. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted.egg-info/scm_file_list.json +7 -0
  23. pytest_impacted-0.37.0/pytest_impacted.egg-info/scm_version.json +8 -0
  24. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/rust/Cargo.lock +33 -22
  25. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/rust/Cargo.toml +1 -1
  26. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/git_helpers.py +16 -0
  27. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_cli.py +202 -189
  28. pytest_impacted-0.37.0/tests/test_cli_config.py +476 -0
  29. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_conftest_integration.py +19 -27
  30. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_extension_integration.py +10 -10
  31. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_extensions.py +31 -0
  32. pytest_impacted-0.37.0/tests/test_file_map_integration.py +449 -0
  33. pytest_impacted-0.37.0/tests/test_ini.py +388 -0
  34. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_invalidation_integration.py +7 -7
  35. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_item_matching.py +4 -4
  36. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_namespace_integration.py +2 -2
  37. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_outside_modules_integration.py +10 -17
  38. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_package_below_package_integration.py +5 -5
  39. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_package_init_integration.py +12 -17
  40. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_plugin.py +4 -0
  41. pytest_impacted-0.37.0/tests/test_unimpacted_integration.py +423 -0
  42. pytest_impacted-0.37.0/uv.lock +824 -0
  43. pytest_impacted-0.35.0/pytest_impacted/cli.py +0 -180
  44. pytest_impacted-0.35.0/pytest_impacted.egg-info/scm_version.json +0 -8
  45. pytest_impacted-0.35.0/uv.lock +0 -746
  46. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.claude/commands/upgrade-all.md +0 -0
  47. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.cursorrules +0 -0
  48. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  49. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  50. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.github/workflows/publish-docs.yml +0 -0
  51. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.github/workflows/publish-rust-wheels.yml +0 -0
  52. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.github/workflows/publish-to-pypi.yml +0 -0
  53. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/.gitignore +0 -0
  54. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/CODE_OF_CONDUCT.md +0 -0
  55. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/CONTRIBUTING.md +0 -0
  56. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/LICENSE +0 -0
  57. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/SECURITY.md +0 -0
  58. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/benchmarks/bench_parsing.py +0 -0
  59. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/docs/assets/favicon.ico +0 -0
  60. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/docs/assets/logo.png +0 -0
  61. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/mkdocs.yml +0 -0
  62. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/__init__.py +0 -0
  63. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/_rust.py +0 -0
  64. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/display.py +0 -0
  65. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/graph.py +0 -0
  66. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/parsing.py +0 -0
  67. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted/traversal.py +0 -0
  68. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted.egg-info/dependency_links.txt +0 -0
  69. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted.egg-info/entry_points.txt +0 -0
  70. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/pytest_impacted.egg-info/top_level.txt +0 -0
  71. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/rust/pyproject.toml +0 -0
  72. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/rust/src/lib.rs +0 -0
  73. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/setup.cfg +0 -0
  74. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/__init__.py +0 -0
  75. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/conftest.py +0 -0
  76. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/__init__.py +0 -0
  77. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/test_ast_impact.py +0 -0
  78. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/test_caching.py +0 -0
  79. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/test_composite_impact.py +0 -0
  80. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/test_conftest_import_impact.py +0 -0
  81. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/test_dependency_file_impact.py +0 -0
  82. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/test_integration.py +0 -0
  83. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/test_invalidation_file_impact.py +0 -0
  84. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/strategies/test_pytest_impact.py +0 -0
  85. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_api.py +0 -0
  86. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_display.py +0 -0
  87. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_git.py +0 -0
  88. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_git_env_isolation.py +0 -0
  89. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_graph.py +0 -0
  90. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_parsing.py +0 -0
  91. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_path_utils.py +0 -0
  92. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_public_api.py +0 -0
  93. {pytest_impacted-0.35.0 → pytest_impacted-0.37.0}/tests/test_traversal.py +0 -0
@@ -0,0 +1,35 @@
1
+ # Weekly dependency-update pull requests against main: the GitHub Actions used by the
2
+ # workflows, the packages pinned in uv.lock and the Rust crate's Cargo.lock. Minor and
3
+ # patch bumps are grouped into one pull request per ecosystem so the CI runs (and the
4
+ # reviews) stay few.
5
+ version: 2
6
+ updates:
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "weekly"
11
+ groups:
12
+ actions:
13
+ patterns: ["*"]
14
+ - package-ecosystem: "uv"
15
+ directory: "/"
16
+ schedule:
17
+ interval: "weekly"
18
+ # ruff stays at the same release as the ruff_python_* git tags in rust/Cargo.toml
19
+ # (see CLAUDE.md), so it is bumped by hand together with them.
20
+ ignore:
21
+ - dependency-name: "ruff"
22
+ groups:
23
+ minor-and-patch:
24
+ update-types: ["minor", "patch"]
25
+ - package-ecosystem: "cargo"
26
+ directory: "/rust"
27
+ schedule:
28
+ interval: "weekly"
29
+ # Pinned by git tag to the ruff release in uv.lock; bumped by hand together with it.
30
+ ignore:
31
+ - dependency-name: "ruff_python_parser"
32
+ - dependency-name: "ruff_python_ast"
33
+ groups:
34
+ minor-and-patch:
35
+ update-types: ["minor", "patch"]
@@ -19,7 +19,7 @@ jobs:
19
19
  id: setup-uv
20
20
  # Downloading uv sometimes fails with a transient "fetch failed"; retried once below.
21
21
  continue-on-error: true
22
- uses: astral-sh/setup-uv@v9.0.0
22
+ uses: astral-sh/setup-uv@v10.3.3
23
23
  with:
24
24
  python-version: "3.13"
25
25
  version: "latest"
@@ -29,7 +29,7 @@ jobs:
29
29
  run: sleep 20
30
30
  - name: Install uv and set the python version (retry)
31
31
  if: steps.setup-uv.outcome == 'failure'
32
- uses: astral-sh/setup-uv@v9.0.0
32
+ uses: astral-sh/setup-uv@v10.3.3
33
33
  with:
34
34
  python-version: "3.13"
35
35
  version: "latest"
@@ -64,7 +64,7 @@ jobs:
64
64
  id: setup-uv
65
65
  # Downloading uv sometimes fails with a transient "fetch failed"; retried once below.
66
66
  continue-on-error: true
67
- uses: astral-sh/setup-uv@v9.0.0
67
+ uses: astral-sh/setup-uv@v10.3.3
68
68
  with:
69
69
  python-version: ${{ matrix.python-version }}
70
70
  version: "latest"
@@ -74,7 +74,7 @@ jobs:
74
74
  run: sleep 20
75
75
  - name: Install uv and set the python version (retry)
76
76
  if: steps.setup-uv.outcome == 'failure'
77
- uses: astral-sh/setup-uv@v9.0.0
77
+ uses: astral-sh/setup-uv@v10.3.3
78
78
  with:
79
79
  python-version: ${{ matrix.python-version }}
80
80
  version: "latest"
@@ -23,7 +23,7 @@ jobs:
23
23
  id: setup-uv
24
24
  # Downloading uv sometimes fails with a transient "fetch failed"; retried once below.
25
25
  continue-on-error: true
26
- uses: astral-sh/setup-uv@v9.0.0
26
+ uses: astral-sh/setup-uv@v10.3.3
27
27
  with:
28
28
  python-version: "3.13"
29
29
  version: "latest"
@@ -33,7 +33,7 @@ jobs:
33
33
  run: sleep 20
34
34
  - name: Install uv and set the python version (retry)
35
35
  if: steps.setup-uv.outcome == 'failure'
36
- uses: astral-sh/setup-uv@v9.0.0
36
+ uses: astral-sh/setup-uv@v10.3.3
37
37
  with:
38
38
  python-version: "3.13"
39
39
  version: "latest"
@@ -69,7 +69,7 @@ jobs:
69
69
  id: setup-uv
70
70
  # Downloading uv sometimes fails with a transient "fetch failed"; retried once below.
71
71
  continue-on-error: true
72
- uses: astral-sh/setup-uv@v9.0.0
72
+ uses: astral-sh/setup-uv@v10.3.3
73
73
  with:
74
74
  python-version: ${{ matrix.python-version }}
75
75
  version: "latest"
@@ -79,7 +79,7 @@ jobs:
79
79
  run: sleep 20
80
80
  - name: Install uv and set the python version (retry)
81
81
  if: steps.setup-uv.outcome == 'failure'
82
- uses: astral-sh/setup-uv@v9.0.0
82
+ uses: astral-sh/setup-uv@v10.3.3
83
83
  with:
84
84
  python-version: ${{ matrix.python-version }}
85
85
  version: "latest"
@@ -92,3 +92,12 @@ jobs:
92
92
  run: uv sync --all-extras --dev
93
93
  - name: Run tests
94
94
  run: uv run pytest
95
+ # The CLI's config reader (ini.py) follows the installed pytest behind version gates, and the
96
+ # steps above run only the locked pytest: this reruns its tests under the older ones it supports.
97
+ - name: Run the config tests under older pytest
98
+ if: matrix.python-version == '3.11' && matrix.backend == 'python'
99
+ run: |
100
+ for version in "8.0.*" "8.4.*" "9.0.*" "9.1.*"; do
101
+ uv run --with "pytest==$version" python -c "import pytest; print('pytest', pytest.__version__); assert pytest.__version__.startswith('$version'.rstrip('*'))"
102
+ uv run --with "pytest==$version" python -m pytest -q tests/test_ini.py tests/test_cli_config.py
103
+ done
@@ -32,7 +32,7 @@ repos:
32
32
  # Keeps uv.lock in sync with pyproject.toml, so a dependency edit cannot be
33
33
  # committed without the corresponding lockfile update.
34
34
  - repo: https://github.com/astral-sh/uv-pre-commit
35
- rev: 0.11.32
35
+ rev: 0.13.5
36
36
  hooks:
37
37
  - id: uv-lock
38
38
  - repo: local
@@ -187,7 +187,7 @@ than returning `None`, because `None` means "nothing changed" and skips every te
187
187
  plugin catches it and **fails open** (runs everything), the CLI exits non-zero. Never
188
188
  collapse "unknown" into "no changes". The notice is printed exactly once: by
189
189
  `pytest_report_header` when git was missing at import (the controller writes the header,
190
- so it survives pytest-xdist), otherwise by the collection hook. Never via `warnings.warn`,
190
+ so it survives pytest-xdist), otherwise by the analysis. Never via `warnings.warn`,
191
191
  which `filterwarnings = error` turns into an INTERNALERROR on the fail-open path.
192
192
 
193
193
  **Branch mode diffs from the merge base**, not the base tip: `_merge_bases` runs
@@ -200,9 +200,9 @@ always uses the tip.
200
200
 
201
201
  **Anything the user must see goes through `display.notify` / `display.warn` with the
202
202
  session.** A `logger` record is swallowed during collection, and `warnings.warn` becomes an
203
- INTERNALERROR under `filterwarnings = error`. Under pytest-xdist even terminal output is
204
- lost (collection runs on the workers), so only `pytest_report_header` reliably reaches the
205
- user there.
203
+ INTERNALERROR under `filterwarnings = error`. Under pytest-xdist a worker's terminal output is
204
+ lost, so the analysis runs on the controller (below), and the rest must be written there:
205
+ `pytest_report_header`, `pytest_terminal_summary`.
206
206
 
207
207
  **Every diff goes through `_name_status_diff` with fixed `--name-status -z --no-renames`.**
208
208
  `-z` stops git C-quoting non-ASCII paths (`core.quotePath`), which would never match a
@@ -255,6 +255,38 @@ every half — each only adds tests. Items import analysis cannot judge always r
255
255
  from non-Python files (`--doctest-glob`, YAML collectors) and `DoctestItem`s — also when
256
256
  nothing at all is impacted.
257
257
 
258
+ **Unselected items are deselected, unless `--impacted-unimpacted=skip`.** pytest exits 5 when
259
+ no test runs, so a run left empty after this plugin deselected anything is turned back into
260
+ exit 0 in `pytest_sessionfinish` (a docs-only commit must pass, as it did when every test was
261
+ skipped, and so must a shard a later plugin handed only deselected tests); one emptied by `-k`
262
+ (which runs first, leaving nothing to deselect) or with nothing collected keeps its 5. Hence two hooks: marking stays at
263
+ the default position, before pytest's `-k`/`-m` (`-m impacted` needs the marker), and the
264
+ deselection is a second, `trylast` `pytest_collection_modifyitems` (`pytest_deselect_unimpacted`,
265
+ via `specname`: pytest registers only `pytest_`-prefixed names) — after `-k`, or a mistyped
266
+ `-k` on a docs-only commit passes. It deselects only the items the first judged: one another
267
+ plugin added in between was never judged, and runs. The exit fix-up is `tryfirst`, so most later
268
+ plugins reading `session.exitstatus` see the final status and any may still set a failure (the
269
+ hooks' `exitstatus` argument stays 5; it cannot be changed).
270
+
271
+ **Under pytest-xdist the controller analyses, once, and the workers only filter.** Each worker
272
+ analysing for itself could disagree with another (a file written in between: git sees the
273
+ working tree), and xdist aborts a run whose workers collect different tests. So
274
+ `pytest_configure_node` (on the controller, before any worker starts) runs `_analyse` and hands
275
+ the impacted files to every worker in `workerinput`, relative to the rootdir; the workers'
276
+ `pytest_collection_modifyitems` takes them from there. Handed on only when every worker would
277
+ compute the same: only built-in strategies enabled (an extension may read what only a worker
278
+ has: `session.items`, `workerinput`), only plain `popen` workers (`--tx` may start another
279
+ interpreter, which parses differently), and an analysis that succeeded (raised in
280
+ `pytest_configure_node` it would escape xdist's session start and skip every
281
+ `pytest_sessionfinish`: no JUnit XML, no combined coverage; it is warned of instead).
282
+ Otherwise each worker analyses for itself and **skips** rather than deselects: workers may
283
+ judge differently, and differing skips abort nothing, differing collections do. That keeps
284
+ every fallback exactly as before 0.36. Review rounds oscillated on this path until it was
285
+ built so; keep it so. The controller collects
286
+ nothing, so each worker reports its deselection through `config.workeroutput`, which
287
+ `pytest_testnodedown` keeps for the exit status and summary. Both are `optionalhook`s: xdist
288
+ need not be installed.
289
+
258
290
  **Changed-file paths are POSIX strings.** `normalize_git_paths` emits `as_posix()` because
259
291
  every matcher is `PurePosixPath`-based; an OS-native Windows path would carry backslashes
260
292
  into the file name and match nothing.
@@ -282,6 +314,23 @@ emits both `pkg` and `pkg.name`; deciding between them would mean importing `pkg
282
314
  disk (`_Linker`), instead. The apparent
283
315
  over-emission is the design, not a bug.
284
316
 
317
+ **The `impacted-tests` CLI reads the pytest configuration through `ini.py`, never a pytest
318
+ `Config`**: building one imports the initial conftests, which is running project code. `ini.py`
319
+ mirrors the installed pytest's search and conversions instead, and `tests/test_ini.py` holds it to
320
+ `pytester.parseconfig` for every file format and precedence rule — when pytest changes how it
321
+ finds or reads configuration, that test is what notices. Each change is followed behind a
322
+ version gate (`PYTEST_8_1`, `PYTEST_9`, `PYTEST_9_2`), never by dropping the old rule: the
323
+ package supports pytest 8.0 and later. Which loader reads a file is pytest's own two tables, by
324
+ file name and then by suffix (`_BY_NAME`, `_BY_SUFFIX`), one loader per pytest function, with the
325
+ gates for it in the tables — a rule threaded through name checks inside suffix loaders is how two
326
+ were missed; the other gates sit in the function mirroring pytest's of the same job (the search,
327
+ `_tool_pytest`, `_pytest_table`, `load_pytest_config`). The test job runs only the locked pytest;
328
+ its 3.11 python job reruns `test_ini.py` and `test_cli_config.py` under older ones, so add a
329
+ version there when a new gate needs one. An option takes its setting only when
330
+ `ctx.get_parameter_source` says the command line left it at its default (`cli._settings`).
331
+ The root stays `--root-dir` (default `.`), as for `pytest --rootdir`, never the file's directory:
332
+ moving it reinterprets an explicit `--module` (two review rounds oscillated on this).
333
+
285
334
  **The Python and Rust backends must agree exactly.** `parsing.py` (astroid) and
286
335
  `rust/src/lib.rs` (ruff parser) both feed `build_dep_tree`, so any divergence silently
287
336
  changes which tests run under the `fast` extra. Known parity points: read with `utf-8-sig`
@@ -348,6 +397,18 @@ Duck-typed strategies need only `find_impacted_tests`: the composite skips the l
348
397
  hooks they lack, and `get_impacted_tests` wraps a bare one in a composite for the same
349
398
  reason.
350
399
 
400
+ **`--impacted-map GLOB=PATH` is no strategy** (`file_map.py`): `get_impacted_tests` adds the
401
+ mapped paths to the changed files, before `link_changed_files`, so every rule and extension
402
+ sees them as it sees an edit. As a strategy re-running `PytestImpactStrategy` on the path, it
403
+ missed the others (a file no walk reaches, `package_members`, the conftest-imports opt-in). A
404
+ path stands for the files git knows there (`git.files_git_knows`: tracked, or untracked and not
405
+ ignored), where changed files come from too — never an `os.walk` (a virtualenv) nor the graph's
406
+ nodes (a file no walk reaches) — spelled exactly, checked by a fresh listing: on macOS git lists
407
+ a wrong-case pathspec as an untracked file. Its parent directories are resolved, the path itself
408
+ not: a symlink git tracks stands for itself, as an edit to it is reported, unless it points at a
409
+ directory. A directory stands for every file git knows in it, not only its Python files. A path git knows nothing at is warned of in
410
+ the report header on every run (it is written by the controller, so xdist shows it too).
411
+
351
412
  **All file globs go through `matches_any_glob`** (`PurePosixPath.match`, right-anchored,
352
413
  `*` never spans `/`, and `**` is *not* recursive — it behaves like a single `*`), and every
353
414
  "this directory and below" match — the conftest rule's `find_test_modules_under`, a changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-impacted
3
- Version: 0.35.0
3
+ Version: 0.37.0
4
4
  Summary: A pytest plugin that selectively runs tests impacted by code changes via git introspection, AST parsing, and dependency graph analysis.
5
5
  Author-email: PromptRomp <promptromp.contact@gmail.com>
6
6
  Maintainer-email: PromptRomp <promptromp.contact@gmail.com>
@@ -26,6 +26,7 @@ License-File: LICENSE
26
26
  Requires-Dist: astroid>=4.1.2
27
27
  Requires-Dist: click>=8.2.0
28
28
  Requires-Dist: gitpython>=3.1.58
29
+ Requires-Dist: iniconfig>=1.0.1
29
30
  Requires-Dist: networkx>=3.4.2
30
31
  Requires-Dist: pytest>=8.0.0
31
32
  Requires-Dist: rich>=14.0.0
@@ -119,7 +120,7 @@ pytest --impacted \
119
120
  --impacted-tests-dir=tests
120
121
  ```
121
122
 
122
- That's it. Unaffected tests are automatically skipped.
123
+ That's it. Unaffected tests are deselected, as `-k` deselects them (`--impacted-unimpacted=skip` marks them skipped instead), and a run whose changes impact no test still passes.
123
124
 
124
125
  ---
125
126
 
@@ -179,15 +180,15 @@ else
179
180
  fi
180
181
  ```
181
182
 
182
- The CLI accepts `--module`, `--git-mode`, `--base-branch`, `--no-merge-base`, `--root-dir`, `--tests-dir`,
183
- `--verbose`, `--no-dep-files`, `--invalidate-all`, `--conftest-imports` and `--disable-ext`, plus an `--impacted-ext-{ext}-{option} VALUE` option for each option of an installed extension (it takes a value, `true` or `false` for a boolean). If your tests live outside the package,
183
+ The CLI accepts `--module`, `--git-mode`, `--base-branch`, `--no-merge-base`, `--root-dir`, `-c/--config-file`, `--tests-dir`,
184
+ `--verbose`, `--no-dep-files`, `--invalidate-all`, `--map`, `--conftest-imports` and `--disable-ext`, each defaulting to its pytest setting (`impacted_module`, …) when one is configured, plus an `--impacted-ext-{ext}-{option} VALUE` option for each option of an installed extension (it takes a value, `true` or `false` for a boolean). If your tests live outside the package,
184
185
  pass `--tests-dir` here as well — see the [usage guide](https://promptromp.github.io/pytest-impacted/usage/#impacted-tests-options).
185
186
 
186
187
  In branch mode, CI must fetch the base ref and enough history to find the fork point — e.g. `fetch-depth: 0` with `actions/checkout`, whose default fetches only the checked-out commit — and name it as the remote-tracking ref (`origin/main`): a PR checkout has no local `main`.
187
188
 
188
189
  ### Configuration via `pyproject.toml`
189
190
 
190
- All pytest options can be set as defaults in your `pyproject.toml` (or `pytest.ini`). The `impacted-tests` CLI reads no config file, so pass its flags explicitly.
191
+ All pytest options can be set as defaults in your `pyproject.toml` (or `pytest.ini`). The `impacted-tests` CLI reads them too (since 0.36), from the file pytest would read for a run from `--root-dir`, so a CI script need not repeat them as flags.
191
192
 
192
193
  ```toml
193
194
  [tool.pytest.ini_options]
@@ -198,8 +199,10 @@ impacted_base_branch = "main"
198
199
  impacted_tests_dir = "tests"
199
200
  # no_impacted_dep_files = true # uncomment to disable dep file detection
200
201
  # impacted_invalidate_all = ["*.json"] # non-Python files that should trigger every test
202
+ # impacted_map = ["reports/*.json=tests/test_bench.py"] # a data file counts as a change to the file it belongs to
201
203
  # impacted_conftest_imports = true # a conftest importing changed app code selects every test beneath it
202
204
  # impacted_no_merge_base = true # branch mode: diff against the base tip, not the fork point
205
+ # impacted_unimpacted = "skip" # mark tests not impacted skipped instead of deselecting them
203
206
  ```
204
207
 
205
208
  Command-line flags override these defaults. A boolean set to `true` here has no flag to turn it off; override it with `-o`, e.g. `-o impacted_conftest_imports=false`.
@@ -216,7 +219,9 @@ Command-line flags override these defaults. A boolean set to `true` here has no
216
219
  | `--impacted-tests-dir` | `None` | Directory containing the tests: needed when they live outside the package, and recommended when inside it (`my_package/tests`), so their fixture modules count as test code |
217
220
  | `--no-impacted-dep-files` | `false` | Disable dependency and test-config file change detection |
218
221
  | `--impacted-invalidate-all` | `[]` | Glob for files that, when changed, mark **all** tests as impacted (repeatable) |
222
+ | `--impacted-map` | `[]` | `GLOB=PATH`: a changed file matching `GLOB` counts as a change to `PATH` — a test file, a module, a `conftest.py` or a directory (repeatable) |
219
223
  | `--impacted-conftest-imports` | `false` | Also select every test beneath a `conftest.py` that imports changed *application* code — see [below](#strategy-based-architecture) |
224
+ | `--impacted-unimpacted` | `deselect` | What becomes of tests not impacted: `deselect` them, or `skip` them (the behaviour up to 0.35) |
220
225
  | `--impacted-disable-ext` | `[]` | Disable a strategy extension by name (repeatable) |
221
226
  | `--impacted-ext-{ext}-{option}` | *(per extension)* | Set a config option on an installed extension (see `pytest --help`) |
222
227
 
@@ -237,8 +242,8 @@ Git diff → Changed files → Module resolution → AST import parsing → Depe
237
242
  4. **Dependency graph** (via [NetworkX](https://networkx.org/)) traces transitive dependencies from changed modules to test modules; a changed package `__init__.py` counts as a change to every module in its package, since Python runs it for any import from it
238
243
  5. **pytest wiring** — a `conftest.py` that changed, or imports changed test code (a fixture module, another conftest), selects every test in its directory and below — and with `--impacted-conftest-imports`, so does one importing changed application code; a change reaching a `pytest_plugins`, `-p` or `PYTEST_PLUGINS` plugin selects all tests
239
244
  6. **Dependency file detection** — if files like `uv.lock`, `requirements*.txt`, `pyproject.toml` or `pytest.ini` changed, all tests are marked as impacted regardless of import analysis
240
- 7. **Invalidation patterns** — user-declared globs for non-Python files (JSON fixtures, SQL schemas, YAML configs, …) that static analysis cannot see; see `--impacted-invalidate-all`
241
- 8. **Test filtering** skips tests whose modules are not in the impact set — a test counts as belonging both to the file it was collected from and to the file it is defined in, so inherited test methods and pytest-bdd scenarios are covered; doctests and tests collected from non-Python files (e.g. `--doctest-glob`) always run
245
+ 7. **Invalidation patterns** — user-declared globs for non-Python files (JSON fixtures, SQL schemas, YAML configs, …) that static analysis cannot see; see `--impacted-invalidate-all`, or `--impacted-map` to run only the tests of the file they belong to
246
+ 8. **Test filtering** deselects tests whose modules are not in the impact set (or skips them, with `--impacted-unimpacted=skip`) — a test counts as belonging both to the file it was collected from and to the file it is defined in, so inherited test methods and pytest-bdd scenarios are covered; doctests and tests collected from non-Python files (e.g. `--doctest-glob`) always run
242
247
 
243
248
  The philosophy is to **err on the side of caution**: we favor false positives (running a test that didn't need to run) over false negatives (missing a test that should have run). The few deliberate exceptions are documented where they apply — most notably, application code used by tests only through a conftest fixture (see `--impacted-conftest-imports`).
244
249
 
@@ -84,7 +84,7 @@ pytest --impacted \
84
84
  --impacted-tests-dir=tests
85
85
  ```
86
86
 
87
- That's it. Unaffected tests are automatically skipped.
87
+ That's it. Unaffected tests are deselected, as `-k` deselects them (`--impacted-unimpacted=skip` marks them skipped instead), and a run whose changes impact no test still passes.
88
88
 
89
89
  ---
90
90
 
@@ -144,15 +144,15 @@ else
144
144
  fi
145
145
  ```
146
146
 
147
- The CLI accepts `--module`, `--git-mode`, `--base-branch`, `--no-merge-base`, `--root-dir`, `--tests-dir`,
148
- `--verbose`, `--no-dep-files`, `--invalidate-all`, `--conftest-imports` and `--disable-ext`, plus an `--impacted-ext-{ext}-{option} VALUE` option for each option of an installed extension (it takes a value, `true` or `false` for a boolean). If your tests live outside the package,
147
+ The CLI accepts `--module`, `--git-mode`, `--base-branch`, `--no-merge-base`, `--root-dir`, `-c/--config-file`, `--tests-dir`,
148
+ `--verbose`, `--no-dep-files`, `--invalidate-all`, `--map`, `--conftest-imports` and `--disable-ext`, each defaulting to its pytest setting (`impacted_module`, …) when one is configured, plus an `--impacted-ext-{ext}-{option} VALUE` option for each option of an installed extension (it takes a value, `true` or `false` for a boolean). If your tests live outside the package,
149
149
  pass `--tests-dir` here as well — see the [usage guide](https://promptromp.github.io/pytest-impacted/usage/#impacted-tests-options).
150
150
 
151
151
  In branch mode, CI must fetch the base ref and enough history to find the fork point — e.g. `fetch-depth: 0` with `actions/checkout`, whose default fetches only the checked-out commit — and name it as the remote-tracking ref (`origin/main`): a PR checkout has no local `main`.
152
152
 
153
153
  ### Configuration via `pyproject.toml`
154
154
 
155
- All pytest options can be set as defaults in your `pyproject.toml` (or `pytest.ini`). The `impacted-tests` CLI reads no config file, so pass its flags explicitly.
155
+ All pytest options can be set as defaults in your `pyproject.toml` (or `pytest.ini`). The `impacted-tests` CLI reads them too (since 0.36), from the file pytest would read for a run from `--root-dir`, so a CI script need not repeat them as flags.
156
156
 
157
157
  ```toml
158
158
  [tool.pytest.ini_options]
@@ -163,8 +163,10 @@ impacted_base_branch = "main"
163
163
  impacted_tests_dir = "tests"
164
164
  # no_impacted_dep_files = true # uncomment to disable dep file detection
165
165
  # impacted_invalidate_all = ["*.json"] # non-Python files that should trigger every test
166
+ # impacted_map = ["reports/*.json=tests/test_bench.py"] # a data file counts as a change to the file it belongs to
166
167
  # impacted_conftest_imports = true # a conftest importing changed app code selects every test beneath it
167
168
  # impacted_no_merge_base = true # branch mode: diff against the base tip, not the fork point
169
+ # impacted_unimpacted = "skip" # mark tests not impacted skipped instead of deselecting them
168
170
  ```
169
171
 
170
172
  Command-line flags override these defaults. A boolean set to `true` here has no flag to turn it off; override it with `-o`, e.g. `-o impacted_conftest_imports=false`.
@@ -181,7 +183,9 @@ Command-line flags override these defaults. A boolean set to `true` here has no
181
183
  | `--impacted-tests-dir` | `None` | Directory containing the tests: needed when they live outside the package, and recommended when inside it (`my_package/tests`), so their fixture modules count as test code |
182
184
  | `--no-impacted-dep-files` | `false` | Disable dependency and test-config file change detection |
183
185
  | `--impacted-invalidate-all` | `[]` | Glob for files that, when changed, mark **all** tests as impacted (repeatable) |
186
+ | `--impacted-map` | `[]` | `GLOB=PATH`: a changed file matching `GLOB` counts as a change to `PATH` — a test file, a module, a `conftest.py` or a directory (repeatable) |
184
187
  | `--impacted-conftest-imports` | `false` | Also select every test beneath a `conftest.py` that imports changed *application* code — see [below](#strategy-based-architecture) |
188
+ | `--impacted-unimpacted` | `deselect` | What becomes of tests not impacted: `deselect` them, or `skip` them (the behaviour up to 0.35) |
185
189
  | `--impacted-disable-ext` | `[]` | Disable a strategy extension by name (repeatable) |
186
190
  | `--impacted-ext-{ext}-{option}` | *(per extension)* | Set a config option on an installed extension (see `pytest --help`) |
187
191
 
@@ -202,8 +206,8 @@ Git diff → Changed files → Module resolution → AST import parsing → Depe
202
206
  4. **Dependency graph** (via [NetworkX](https://networkx.org/)) traces transitive dependencies from changed modules to test modules; a changed package `__init__.py` counts as a change to every module in its package, since Python runs it for any import from it
203
207
  5. **pytest wiring** — a `conftest.py` that changed, or imports changed test code (a fixture module, another conftest), selects every test in its directory and below — and with `--impacted-conftest-imports`, so does one importing changed application code; a change reaching a `pytest_plugins`, `-p` or `PYTEST_PLUGINS` plugin selects all tests
204
208
  6. **Dependency file detection** — if files like `uv.lock`, `requirements*.txt`, `pyproject.toml` or `pytest.ini` changed, all tests are marked as impacted regardless of import analysis
205
- 7. **Invalidation patterns** — user-declared globs for non-Python files (JSON fixtures, SQL schemas, YAML configs, …) that static analysis cannot see; see `--impacted-invalidate-all`
206
- 8. **Test filtering** skips tests whose modules are not in the impact set — a test counts as belonging both to the file it was collected from and to the file it is defined in, so inherited test methods and pytest-bdd scenarios are covered; doctests and tests collected from non-Python files (e.g. `--doctest-glob`) always run
209
+ 7. **Invalidation patterns** — user-declared globs for non-Python files (JSON fixtures, SQL schemas, YAML configs, …) that static analysis cannot see; see `--impacted-invalidate-all`, or `--impacted-map` to run only the tests of the file they belong to
210
+ 8. **Test filtering** deselects tests whose modules are not in the impact set (or skips them, with `--impacted-unimpacted=skip`) — a test counts as belonging both to the file it was collected from and to the file it is defined in, so inherited test methods and pytest-bdd scenarios are covered; doctests and tests collected from non-Python files (e.g. `--doctest-glob`) always run
207
211
 
208
212
  The philosophy is to **err on the side of caution**: we favor false positives (running a test that didn't need to run) over false negatives (missing a test that should have run). The few deliberate exceptions are documented where they apply — most notably, application code used by tests only through a conftest fixture (see `--impacted-conftest-imports`).
209
213
 
@@ -38,7 +38,7 @@ impacted = get_impacted_tests(
38
38
 
39
39
  `get_impacted_tests()` returns the impacted test files, or `None` when nothing is impacted. It raises `pytest_impacted.git.GitUnavailableError` when git cannot run, because then the changes are *unknown* — treat that as "run everything", never as "nothing to run".
40
40
 
41
- The strategy you pass **replaces** the default pipeline — the AST, conftest and dependency-file strategies included, and `watch_dep_files` / `invalidate_all_patterns` / `conftest_imports` then have no effect. To add to the defaults instead, pass `CompositeImpactStrategy([*get_default_strategies(), MyCustomStrategy()])` (both from `pytest_impacted.strategies`).
41
+ The strategy you pass **replaces** the default pipeline — the AST, conftest and dependency-file strategies included, and `watch_dep_files` / `invalidate_all_patterns` / `conftest_imports` then have no effect (`file_map` still does: its paths join `changed_files`, which every strategy receives). To add to the defaults instead, pass `CompositeImpactStrategy([*get_default_strategies(), MyCustomStrategy()])` (both from `pytest_impacted.strategies`).
42
42
 
43
43
  This is the right entry point for one-off integrations or for driving impact analysis from your own test runner. For reusable, auto-discovered strategies that ship as their own package, see the packaged extension system below.
44
44
 
@@ -240,6 +240,8 @@ class MyScanningStrategy(ImpactStrategy):
240
240
 
241
241
  `ImpactStrategy` exposes three optional lifecycle methods that run once per pytest invocation: `enrich_dep_tree`, `setup`, and `teardown`. They give extensions proper places to hang one-time work and — critically — to inject synthetic dependency edges that the built-in AST traversal will then follow automatically.
242
242
 
243
+ **Where the pipeline runs.** Every hook and `find_impacted_tests` run during collection, in the process that runs the tests: under pytest-xdist, in each worker, with that worker's session. (With only the built-in strategies, pytest-xdist's controller analyses once instead and hands every worker the result, since workers analysing for themselves could disagree; an installed extension keeps the analysis in the workers, where it may rely on what only a worker has, and the workers then skip rather than deselect the tests they find unimpacted, so that two of them judging differently stop nothing. Disable one with `--impacted-disable-ext` and the controller analyses again.)
244
+
243
245
  ### `setup` and `teardown` — one-time work per run
244
246
 
245
247
  ```python
@@ -437,6 +439,7 @@ The extension system is designed to be fault-tolerant:
437
439
  - **Instantiation errors**: If a strategy's `__init__` raises an exception, the extension is skipped.
438
440
  - **Invalid classes**: If an entry point resolves to a class without `find_impacted_tests`, it is skipped with a warning.
439
441
  - **Missing required options**: A `ConfigOption(required=True)` with no value skips the extension with a warning.
442
+ - **Option values**: An empty setting (`impacted_ext_demo_threshold =`) is unset, so the option's default applies. One that does not convert to the option's `type` fails the run with an error naming the extension, the option and the value (a usage error in the `impacted-tests` CLI).
440
443
  - **Lifecycle hooks**: Exceptions from `enrich_dep_tree`, `setup` or `teardown` are logged and that phase is skipped for the strategy; the others carry on.
441
444
 
442
445
  A failure to load an entry point (an import error, or an entry point that is not a strategy class) happens while pytest registers options, before it configures logging, so it is printed to stderr on every run (an import error with its traceback). The other warnings are log records on the `pytest_impacted.extensions` / `pytest_impacted.strategies` loggers emitted during collection, not shown in pytest's terminal output by default (use `--log-cli-level=WARNING` to see them).
@@ -20,6 +20,16 @@ This runs only the tests impacted by files with uncommitted changes (staged or u
20
20
  The `--impacted-module` value must be a valid Python package name (underscores, not hyphens).
21
21
  If you accidentally use hyphens, the plugin will suggest the corrected name.
22
22
 
23
+ ### Tests not impacted
24
+
25
+ Tests no change impacts are **deselected**, as `-k` and `-m` deselect theirs: they are left out of the run and its reports (verbose output, JUnit XML), and the summary counts them (`2 passed, 812 deselected`). A line at the end of the run says how many were left out as not impacted, which under pytest-xdist, whose summary has no deselected count, is the only place it shows.
26
+
27
+ A run whose changes impact no test, such as a docs-only commit, exits with status 0, as does a shard a sharding plugin handed only deselected tests. pytest itself exits with status 5 when no test runs; that still happens when the plugin deselected nothing (`-k` matching no test, or no tests collected at all). A run another plugin empties after this one deselected some, such as `--lf --lfnf=none` with no failures recorded, exits with status 0 too.
28
+
29
+ Under pytest-xdist the analysis runs once, on the controller, and every worker filters by its result: workers analysing for themselves could disagree, and xdist stops a run whose workers collect different tests. Its notices are then shown too. With a strategy extension installed, with `--tx` workers, or when the analysis fails on the controller (a warning says so), each worker analyses for itself instead, as before 0.36, and marks the tests it finds unimpacted **skipped**, whatever `--impacted-unimpacted` says: tests skipped differently by two workers stop nothing, while tests collected differently would stop the run. The workers' notices are then not shown, as before.
30
+
31
+ To mark them skipped instead, as releases up to 0.35 did, pass `--impacted-unimpacted=skip` (ini: `impacted_unimpacted = "skip"`). Each then reports `SKIPPED (not impacted by the changes)`. `--impacted-unimpacted=deselect` restores the default when the ini says `skip`.
32
+
23
33
  ## Git Modes
24
34
 
25
35
  ### Unstaged Mode (default)
@@ -122,7 +132,7 @@ The package's own `__init__.py` is a module too. A test that imports from the pa
122
132
 
123
133
  **Package `__init__.py` files.** Python runs every package's `__init__.py` above a module before the module itself: `from my_package.core.x import f` runs `my_package/__init__.py` and `my_package/core/__init__.py` too, though it names neither. So (since 0.34) editing, adding or deleting an `__init__.py` — the package root's, a sub-package's, one in the tests directory, or one above `--impacted-module` (`backend/__init__.py` for `backend/app`) — counts as a change to every module inside its package. That selects every test importing anything inside the package, directly or not — even a module missing from it, as an optional import in `try`/`except ImportError` is — and, for tests kept inside the package or in a tests directory that is itself a package (with `__init__.py`), every test beneath it. The pytest rules see those modules as changed too: a conftest importing one selects the tests beneath it (for application code, only with `--impacted-conftest-imports`), and a package holding a `pytest_plugins` module selects every test. It is only the `__init__.py` itself that reaches the whole package: a module it imports (a re-export) is linked to the tests that import from the package root by name, not to every test importing a sub-module, although Python runs it for those too. An `__init__.py` above the rootdir (in a monorepo holding the project) changes nothing, since imports start inside the rootdir — unless every directory from it down to the rootdir is a package too, when pytest may import your test modules through it: then every test is selected.
124
134
 
125
- **Modules outside the analysed directories.** An import that names no module in `--impacted-module` or `--impacted-tests-dir` is looked up on disk — never imported — under the rootdir and every directory the analysed modules' own names are rooted at (`src/` for `src/my_package`, `backend/` for a tests dir `backend/tests` whose modules import as `tests.x`), the directories in between that are not regular packages (no `__init__.py`), and every directory above `--impacted-module` or `--impacted-tests-dir`, a package or not (since 0.35; never one inside the analysed package). When such a directory is itself a package, or inside one, like `src/` with an `__init__.py`, it is used for names that spell your package from it (`my_package.x`), and for other names only once your code imports the package that way somewhere — never for a standard-library name, since a `logging.py` in a directory really on `sys.path` would shadow the standard library. Not yet the directory pytest itself puts on `sys.path` for a test module outside any package: `import helpers` beside such a test module links to nothing. A file found there joins the graph and is followed like any other module, together with what it imports: a fixture helper in `testing/factories.py` imported by a conftest, a shared library in `src/shared/` your package imports, or a `pytest_plugins` module kept outside both directories. It counts as a test module only if its path from the rootdir looks like one, as for any module. A local package named like a standard-library module (`profile/`, `email/`) is followed too, since with your project first on `sys.path` it shadows the standard library's; a distribution installed into the project directory (`pip install -t .`, with its `.dist-info`) is not. A changed Python file outside the analysed directories that no test depends on — a script, a migration, or a deleted module only untested code imported — is named in a notice, since import analysis selects no tests for it (printed during collection, so not shown under pytest-xdist; a deleted file nothing imports needs none). If tests use it some other way, such as running it as a subprocess, list it in `--impacted-invalidate-all`.
135
+ **Modules outside the analysed directories.** An import that names no module in `--impacted-module` or `--impacted-tests-dir` is looked up on disk — never imported — under the rootdir and every directory the analysed modules' own names are rooted at (`src/` for `src/my_package`, `backend/` for a tests dir `backend/tests` whose modules import as `tests.x`), the directories in between that are not regular packages (no `__init__.py`), and every directory above `--impacted-module` or `--impacted-tests-dir`, a package or not (since 0.35; never one inside the analysed package). When such a directory is itself a package, or inside one, like `src/` with an `__init__.py`, it is used for names that spell your package from it (`my_package.x`), and for other names only once your code imports the package that way somewhere — never for a standard-library name, since a `logging.py` in a directory really on `sys.path` would shadow the standard library. Not yet the directory pytest itself puts on `sys.path` for a test module outside any package: `import helpers` beside such a test module links to nothing. A file found there joins the graph and is followed like any other module, together with what it imports: a fixture helper in `testing/factories.py` imported by a conftest, a shared library in `src/shared/` your package imports, or a `pytest_plugins` module kept outside both directories. It counts as a test module only if its path from the rootdir looks like one, as for any module. A local package named like a standard-library module (`profile/`, `email/`) is followed too, since with your project first on `sys.path` it shadows the standard library's; a distribution installed into the project directory (`pip install -t .`, with its `.dist-info`) is not. A changed Python file outside the analysed directories that no test depends on — a script, a migration, or a deleted module only untested code imported — is named in a notice, since import analysis selects no tests for it (a deleted file nothing imports needs none). If tests use it some other way, such as running it as a subprocess, list it in `--impacted-invalidate-all`.
126
136
 
127
137
  **Deleted modules.** A deleted module that something still imports — inside a function, behind `try`/`except ImportError`, or through a module no test collects — selects the tests of whatever still imports it, so they fail, as they should, rather than being skipped. (An import at the top of a test module already fails its collection.)
128
138
 
@@ -140,14 +150,14 @@ Extends the AST analysis with pytest-specific dependency detection:
140
150
 
141
151
  ### ConftestImportImpactStrategy (opt-in)
142
152
 
143
- Always in the default pipeline, but by default it only *reports*: a notice names the conftests that import changed application code (it is printed during collection, so not shown under pytest-xdist). Enabled with `--impacted-conftest-imports` (ini: `impacted_conftest_imports = true`; `impacted-tests` CLI: `--conftest-imports`), it selects too: a conftest that imports changed *application* code, directly or through other modules, then impacts every test in its directory and below, exactly as an edited conftest does. A `db` fixture built on `app/db.py` means a change to `app/db.py` impacts every test under that conftest, even though no test imports `app/db.py` itself. Modules outside `--impacted-module` and `--impacted-tests-dir` are followed too when an analysed module imports them (see [ASTImpactStrategy](#astimpactstrategy)).
153
+ Always in the default pipeline, but by default it only *reports*: a notice names the conftests that import changed application code. Enabled with `--impacted-conftest-imports` (ini: `impacted_conftest_imports = true`; `impacted-tests` CLI: `--conftest-imports`), it selects too: a conftest that imports changed *application* code, directly or through other modules, then impacts every test in its directory and below, exactly as an edited conftest does. A `db` fixture built on `app/db.py` means a change to `app/db.py` impacts every test under that conftest, even though no test imports `app/db.py` itself. Modules outside `--impacted-module` and `--impacted-tests-dir` are followed too when an analysed module imports them (see [ASTImpactStrategy](#astimpactstrategy)).
144
154
 
145
155
  *Application code* is what discovering `--impacted-module` finds, less conftests and anything `--impacted-tests-dir` finds too. So if your tests live inside the package, pass `--impacted-tests-dir` (e.g. `my_package/tests`): without it their fixture modules count as application code, and a conftest importing them is only followed with this option. (A tests dir holding the whole package cannot tell the two apart and is ignored for this.) A module outside both directories that the graph follows is application code when application code imports it — a shared library — and test code otherwise, like a fixture helper; a deleted module is placed the same way, by what still imports it. An import that resolves only from a directory above the analysed ones that no module name is rooted at — a package itself, like `src/` with an `__init__.py` (`import shared` for `src/shared.py`), or a directory inside one — does not count for this: whether that directory is on `sys.path` is a guess, so the module stays test code, which is followed. That includes a module deleted from the package that the application imported that way: a conftest reaching it selects the tests beneath it.
146
156
 
147
157
  !!! warning "The trade-off"
148
158
  Tests never import their conftest — pytest injects its fixtures by name — so **without this option, a test that uses changed application code only through a conftest fixture is not selected**. This is a deliberate exception to erring on the side of caution, like the `pytest_plugins` limitations above. The option closes the gap, but coarsely: a top-level `tests/conftest.py` that imports your application (an app factory, a database session) makes almost every change select almost every test. It was the default in 0.31.0 and turned typical edits into full runs, which is why it is now opt-in.
149
159
 
150
- Turn it on where missing a fixture-only dependency costs more than a longer run — for example in a pre-merge CI job. Pass it on that job's command line (`--impacted-conftest-imports`, or `--conftest-imports` for the `impacted-tests` CLI, which does not read the ini) rather than in the ini: an ini `true` cannot be switched off from the command line except with `-o impacted_conftest_imports=false`.
160
+ Turn it on where missing a fixture-only dependency costs more than a longer run — for example in a pre-merge CI job. Pass it on that job's command line (`--impacted-conftest-imports`, or `--conftest-imports` for the `impacted-tests` CLI) rather than in the ini: an ini `true` cannot be switched off from the pytest command line except with `-o impacted_conftest_imports=false` (the CLI has `--no-conftest-imports`).
151
161
 
152
162
  ```bash
153
163
  pytest --impacted --impacted-module=my_package --impacted-conftest-imports
@@ -207,6 +217,34 @@ Patterns are matched against each changed file's path as reported to the strateg
207
217
  !!! note
208
218
  This is independent of `--no-impacted-dep-files`, which only switches off the built-in dependency-file list. Custom invalidation patterns stay active either way.
209
219
 
220
+ ### Mapping files to the code they belong to
221
+
222
+ When a data file belongs to particular tests, invalidating every test is more than you need. `--impacted-map GLOB=PATH` (since 0.36) says which file it belongs to: a changed file matching `GLOB` counts as a change to `PATH`, a file or directory relative to the rootdir, and the run selects what an edit to `PATH` would:
223
+
224
+ | `PATH` | Selects |
225
+ |---|---|
226
+ | a test file | that test file |
227
+ | a module | the tests that import it, directly or through other modules (and, with `--impacted-conftest-imports`, the tests beneath a conftest importing it) |
228
+ | a package `__init__.py` | the tests of every module in its package |
229
+ | a `conftest.py` | every test in its directory and below |
230
+ | a directory | what an edit to every file git knows in it and below would (tracked, or untracked and not ignored: a virtualenv git ignores is left out) |
231
+ | a dependency file (`pyproject.toml`, ...) | every test |
232
+
233
+ ```bash
234
+ pytest --impacted --impacted-module=my_package --impacted-tests-dir=tests \
235
+ --impacted-map='reports/*.json=tests/test_bench.py' \
236
+ --impacted-map='schema/*.sql=my_package/db.py'
237
+ ```
238
+
239
+ Or in `pyproject.toml`:
240
+
241
+ ```toml
242
+ [tool.pytest.ini_options]
243
+ impacted_map = ["reports/*.json=tests/test_bench.py", "schema/*.sql=my_package/db.py"]
244
+ ```
245
+
246
+ `GLOB` is matched as `--impacted-invalidate-all` globs are (see above); a glob may map to several paths, one entry each, and a mapped file another glob matches is mapped on. `PATH` must be relative and inside the rootdir, and is spelled as on disk, case included. A symlink stands for itself, as an edit to it is reported, unless it points at a directory, which it then stands for; a path through a symlinked directory reaches the file it leads to. One git knows no file at is named in a notice, since it selects nothing. The mapped paths join the changed files before any strategy runs, so every strategy, an extension's included, sees them as changed. The `impacted-tests` CLI takes `--map GLOB=PATH`.
247
+
210
248
  ### CompositeImpactStrategy
211
249
 
212
250
  Combines multiple strategies, deduplicating and sorting results. The default composition is:
@@ -261,22 +299,30 @@ impacted-tests --module=my_package --tests-dir=tests --git-mode=branch --base-br
261
299
 
262
300
  | Option | Default | Description |
263
301
  |--------|---------|-------------|
264
- | `--module` | *(required)* | Namespace (top-level) module for the package under test |
302
+ | `--module` | *(required, here or in the configuration)* | Namespace (top-level) module for the package under test |
265
303
  | `--git-mode` | `unstaged` | Git comparison mode: `unstaged` or `branch` |
266
304
  | `--base-branch` | `main` | Base branch/ref for branch-mode comparison |
267
- | `--no-merge-base` | `false` | In branch mode, diff against the base branch's tip instead of the fork point |
305
+ | `--no-merge-base` / `--merge-base` | `false` | In branch mode, diff against the base branch's tip instead of the fork point |
268
306
  | `--root-dir` | `.` | Root directory of the project repository; `--module` and `--tests-dir` are relative to it |
307
+ | `-c`, `--config-file` | *(found as pytest finds it)* | The pytest configuration file to take defaults from |
269
308
  | `--tests-dir` | `None` | Directory containing test files outside the namespace module |
270
309
  | `--verbose` | `false` | Verbose output (written to stderr, so it will not pollute the piped test list) |
271
- | `--no-dep-files` | `false` | Disable dependency and test-config file change detection |
310
+ | `--no-dep-files` / `--dep-files` | `false` | Disable dependency and test-config file change detection |
272
311
  | `--invalidate-all` | `[]` | Glob for files that, when changed, mark all tests as impacted (repeatable) |
273
- | `--conftest-imports` | `false` | Also mark every test beneath a `conftest.py` that imports changed application code as impacted |
312
+ | `--map` | `[]` | `GLOB=PATH`: a changed file matching `GLOB` counts as a change to `PATH` (repeatable) |
313
+ | `--conftest-imports` / `--no-conftest-imports` | `false` | Also mark every test beneath a `conftest.py` that imports changed application code as impacted |
274
314
  | `--disable-ext` | `[]` | Disable a strategy extension by name (repeatable) |
275
315
  | `--impacted-ext-{ext}-{option}` | *(per extension)* | Set a config option on an installed extension; it takes a value, `true` or `false` for a boolean. Run `impacted-tests --help` to list them |
276
316
 
317
+ #### Settings from the pytest configuration
318
+
319
+ An option left off the command line takes its pytest setting, the one the plugin reads: `impacted_module` for `--module`, `impacted_git_mode`, `impacted_base_branch`, `impacted_no_merge_base`, `impacted_tests_dir`, `no_impacted_dep_files`, `impacted_invalidate_all`, `impacted_map`, `impacted_conftest_imports`, `impacted_disable_ext`, and `impacted_ext_{ext}_{option}` for an extension's option. Only then does it take the default above. A flag given wins, and each boolean has a flag to turn it off (`--no-conftest-imports`), so an ini `true` can be overridden.
320
+
321
+ The settings come from the file pytest would read for a run from `--root-dir`: the nearest directory, from there up, holding a `pytest.toml`, `.pytest.toml`, `pytest.ini`, `.pytest.ini`, `pyproject.toml` with a `[tool.pytest]` or `[tool.pytest.ini_options]` table, `tox.ini` with `[pytest]`, or `setup.cfg` with `[tool:pytest]`, in that order. (pytest 8 reads no `pytest.toml` and no `[tool.pytest]`, and neither then does the CLI.) `-c FILE` names one instead, as pytest's `-c` does. With pytest 9.2 and later, as with pytest, a regular file with a suffix other than `.toml`, `.ini` or `.cfg` is a usage error (a path that is no regular file, such as `-c /dev/null`, reads as no configuration), and a `.toml` file not named `pytest.toml`, `.pytest.toml` or `pyproject.toml` is read from its `[pytest]` table, as a `pytest.toml` is, unless it has `[tool.pytest]` tables; options outside any table of a `pytest.toml`, `.pytest.toml` or such a file are a usage error, not passed over. The CLI prints the file it read as `config-file:`. A file it cannot read is a usage error, as it is for pytest, rather than passed over with its settings lost. Paths in the settings are relative to `--root-dir`, whichever directory the file is in, as they are for `pytest --rootdir=<root-dir>`: running from a service directory of a monorepo, `--module` and `impacted_module` both name a package there. Only these settings are read: not `addopts`, and no `-o` overrides; nor is any conftest loaded, as the CLI runs no project code.
322
+
277
323
  ## Configuration via `pyproject.toml`
278
324
 
279
- All pytest options can be set as defaults in your `pyproject.toml` (or `pytest.ini`). The `impacted-tests` CLI reads no config file, so pass its flags explicitly.
325
+ All pytest options can be set as defaults in your `pyproject.toml` (or `pytest.ini`). The `impacted-tests` CLI reads them too (since 0.36), from the file pytest would read for a run from `--root-dir`, so a CI script need not repeat them as flags. See [where the CLI reads them](#settings-from-the-pytest-configuration).
280
326
 
281
327
  ```toml
282
328
  [tool.pytest.ini_options]
@@ -287,7 +333,9 @@ impacted_base_branch = "main"
287
333
  impacted_tests_dir = "tests"
288
334
  no_impacted_dep_files = false # set to true to disable dep file detection
289
335
  impacted_invalidate_all = ["*.json"] # non-Python files that should trigger every test
336
+ impacted_map = ["reports/*.json=tests/test_bench.py"] # a changed data file counts as a change to the file it belongs to
290
337
  impacted_conftest_imports = false # true: a conftest importing changed app code selects every test beneath it
338
+ impacted_unimpacted = "deselect" # "skip": mark tests not impacted skipped instead of deselecting them
291
339
  impacted_no_merge_base = false # true: branch mode diffs against the base tip
292
340
  impacted_disable_ext = [] # extension names to disable
293
341
  ```
@@ -308,7 +356,7 @@ The plugin validates configuration early and provides helpful error messages:
308
356
  | `--impacted-base-branch=--some-option` | Rejected before reaching git — refs may not begin with `-`, since git would parse them as options rather than revisions |
309
357
  | No git repository found (branch mode) | Clear error naming the rootdir searched: no `.git` found at or above it |
310
358
  | No git repository found (unstaged mode) | Not validated up front — the failure surfaces from GitPython during collection |
311
- | git executable not installed (or GitPython missing) | **Fails open**: every test runs. If git was missing when the plugin loaded, a `WARNING` line in the report header says so; if it fails only when invoked, a terminal warning does (not shown under pytest-xdist). The `impacted-tests` CLI exits with status 1 instead of printing an empty list. When git *is* available, a missing repository is different — that is a configuration error and stays one |
359
+ | git executable not installed (or GitPython missing) | **Fails open**: every test runs. If git was missing when the plugin loaded, a `WARNING` line in the report header says so; if it fails only when invoked, a terminal warning does. The `impacted-tests` CLI exits with status 1 instead of printing an empty list. When git *is* available, a missing repository is different — that is a configuration error and stays one |
312
360
 
313
361
  ## All Options
314
362
 
@@ -322,7 +370,9 @@ The plugin validates configuration early and provides helpful error messages:
322
370
  | `--impacted-tests-dir` | `None` | Directory containing tests outside the package |
323
371
  | `--no-impacted-dep-files` | `false` | Disable dependency and test-config file change detection |
324
372
  | `--impacted-invalidate-all` | `[]` | Glob for files that, when changed, mark all tests as impacted (repeatable) |
373
+ | `--impacted-map` | `[]` | `GLOB=PATH`: a changed file matching `GLOB` counts as a change to `PATH`, a file or directory (repeatable; [details](#mapping-files-to-the-code-they-belong-to)) |
325
374
  | `--impacted-conftest-imports` | `false` | Also mark every test beneath a `conftest.py` that imports changed application code as impacted ([details](#conftestimportimpactstrategy-opt-in)) |
375
+ | `--impacted-unimpacted` | `deselect` | What becomes of tests not impacted: `deselect` them, or `skip` them ([details](#tests-not-impacted)) |
326
376
  | `--impacted-disable-ext` | `[]` | Disable a strategy extension by name (repeatable) |
327
377
  | `--impacted-ext-{ext}-{option}` | *(per extension)* | Set a config option on an installed extension. Installed extensions register their own flags — run `pytest --help` to list them, or see the [Extensions guide](extensions.md#extension-with-configuration) |
328
378
 
@@ -341,6 +391,8 @@ graph LR
341
391
  F -->|uv.lock, requirements*.txt, pytest.ini, etc.| G
342
392
  B --> H[Invalidation patterns]
343
393
  H -->|--impacted-invalidate-all| G
394
+ B --> M[File mappings]
395
+ M -->|--impacted-map| C
344
396
  ```
345
397
 
346
398
  1. **Git introspection** identifies which files changed (uncommitted edits staged or not, untracked files and deletions, or a branch diff)
@@ -349,8 +401,8 @@ graph LR
349
401
  4. **Dependency graph** (via [NetworkX](https://networkx.org/)) traces transitive dependencies from changed modules to test modules; a changed package `__init__.py` counts as a change to every module in its package, since Python runs it for any import from it
350
402
  5. **pytest-aware rules** — a `conftest.py` that changed, or imports changed test code, selects every test in its directory and below — and with `--impacted-conftest-imports`, so does one importing changed application code; a change reaching a `pytest_plugins`, `-p` or `PYTEST_PLUGINS` plugin selects every test
351
403
  6. **Dependency file detection** — if files like `uv.lock`, `requirements*.txt`, `pyproject.toml` or `pytest.ini` changed, all tests are marked as impacted regardless of import analysis
352
- 7. **Invalidation patterns** — user-declared globs for non-Python files that static analysis cannot see (see [InvalidationFileImpactStrategy](#invalidationfileimpactstrategy))
353
- 8. **Test filtering** skips tests whose modules are not in the impact set — a test counts as belonging both to the file it was collected from and to the file it is defined in, so inherited test methods and pytest-bdd scenarios are covered; doctests and tests collected from non-Python files (e.g. `--doctest-glob`) always run
404
+ 7. **Invalidation patterns** — user-declared globs for non-Python files that static analysis cannot see (see [InvalidationFileImpactStrategy](#invalidationfileimpactstrategy)), or user-declared mappings from them to the file they belong to (see [Mapping files to the code they belong to](#mapping-files-to-the-code-they-belong-to))
405
+ 8. **Test filtering** deselects tests whose modules are not in the impact set (or skips them, with `--impacted-unimpacted=skip`) — a test counts as belonging both to the file it was collected from and to the file it is defined in, so inherited test methods and pytest-bdd scenarios are covered; doctests and tests collected from non-Python files (e.g. `--doctest-glob`) always run
354
406
 
355
407
  The philosophy is to **err on the side of caution**: false positives (running a test that didn't need to run) are preferred over false negatives (missing a test that should have run). The few deliberate exceptions are documented where they apply — most notably [application code used only through a conftest fixture](#conftestimportimpactstrategy-opt-in).
356
408
 
@@ -38,6 +38,8 @@ dependencies = [
38
38
  # GHSA-wvpp-8hx9-p66j, GHSA-hh9p-6wh2-4mfc, GHSA-9rj7-rf2p-w77r,
39
39
  # GHSA-4gmw-gg2m-w46p (and the earlier <= 3.1.51 injection advisories).
40
40
  "gitpython>=3.1.58",
41
+ # pytest's own ini parser, for the impacted-tests CLI to read ini files as pytest does.
42
+ "iniconfig>=1.0.1",
41
43
  "networkx>=3.4.2",
42
44
  "pytest>=8.0.0",
43
45
  "rich>=14.0.0",
@@ -63,6 +65,7 @@ dev = [
63
65
  "mypy>=1.15.0",
64
66
  "pre-commit>=4.6.1",
65
67
  "pytest-cov>=6.1.1",
68
+ "pytest-xdist>=3.8.0",
66
69
  "ruff>=0.11.9",
67
70
  ]
68
71