pytest-filemon 0.1.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.
- pytest_filemon-0.1.0/.github/workflows/ci.yml +44 -0
- pytest_filemon-0.1.0/.github/workflows/publish.yml +65 -0
- pytest_filemon-0.1.0/.gitignore +8 -0
- pytest_filemon-0.1.0/.python-version +1 -0
- pytest_filemon-0.1.0/LICENSE +202 -0
- pytest_filemon-0.1.0/PKG-INFO +206 -0
- pytest_filemon-0.1.0/README.md +183 -0
- pytest_filemon-0.1.0/pyproject.toml +54 -0
- pytest_filemon-0.1.0/src/pytest_filemon/__init__.py +12 -0
- pytest_filemon-0.1.0/src/pytest_filemon/fingerprint.py +334 -0
- pytest_filemon-0.1.0/src/pytest_filemon/imports.py +402 -0
- pytest_filemon-0.1.0/src/pytest_filemon/plugin.py +577 -0
- pytest_filemon-0.1.0/src/pytest_filemon/selection.py +134 -0
- pytest_filemon-0.1.0/src/pytest_filemon/store.py +147 -0
- pytest_filemon-0.1.0/src/pytest_filemon/util.py +87 -0
- pytest_filemon-0.1.0/tests/conftest.py +31 -0
- pytest_filemon-0.1.0/tests/test_core.py +243 -0
- pytest_filemon-0.1.0/uv.lock +262 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
dogfood:
|
|
10
|
+
# The plugin's own suite through the plugin itself: the first run
|
|
11
|
+
# records, the no-change rerun must select nothing (and exit 0).
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: astral-sh/setup-uv@v5
|
|
16
|
+
|
|
17
|
+
- name: Install
|
|
18
|
+
run: uv sync
|
|
19
|
+
|
|
20
|
+
- name: Run tests (filemon dogfood)
|
|
21
|
+
run: |
|
|
22
|
+
uv run pytest --filemon -q tests # records: everything runs
|
|
23
|
+
uv run pytest --filemon -q tests # nothing changed: 0 selected, exit 0
|
|
24
|
+
|
|
25
|
+
tests:
|
|
26
|
+
# The plain suite on every supported Python.
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
strategy:
|
|
29
|
+
fail-fast: false
|
|
30
|
+
matrix:
|
|
31
|
+
python: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v4
|
|
34
|
+
- uses: astral-sh/setup-uv@v5
|
|
35
|
+
- run: uv sync --python ${{ matrix.python }}
|
|
36
|
+
- run: uv run --python ${{ matrix.python }} pytest -q tests
|
|
37
|
+
|
|
38
|
+
lint:
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/checkout@v4
|
|
42
|
+
- uses: astral-sh/setup-uv@v5
|
|
43
|
+
- run: uv sync
|
|
44
|
+
- run: uv run ruff check src tests
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
inputs:
|
|
8
|
+
target:
|
|
9
|
+
description: Where to publish
|
|
10
|
+
required: true
|
|
11
|
+
default: testpypi
|
|
12
|
+
type: choice
|
|
13
|
+
options:
|
|
14
|
+
- testpypi
|
|
15
|
+
- pypi
|
|
16
|
+
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
build:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: astral-sh/setup-uv@v5
|
|
26
|
+
|
|
27
|
+
- run: uv sync
|
|
28
|
+
- run: uv run pytest -q tests
|
|
29
|
+
- run: uv build
|
|
30
|
+
|
|
31
|
+
- uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: dist
|
|
34
|
+
path: dist/
|
|
35
|
+
if-no-files-found: error
|
|
36
|
+
|
|
37
|
+
publish-testpypi:
|
|
38
|
+
needs: build
|
|
39
|
+
if: github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi'
|
|
40
|
+
runs-on: ubuntu-latest
|
|
41
|
+
environment: testpypi
|
|
42
|
+
permissions:
|
|
43
|
+
id-token: write
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/download-artifact@v4
|
|
46
|
+
with:
|
|
47
|
+
name: dist
|
|
48
|
+
path: dist/
|
|
49
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
50
|
+
with:
|
|
51
|
+
repository-url: https://test.pypi.org/legacy/
|
|
52
|
+
|
|
53
|
+
publish-pypi:
|
|
54
|
+
needs: build
|
|
55
|
+
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.target == 'pypi')
|
|
56
|
+
runs-on: ubuntu-latest
|
|
57
|
+
environment: pypi
|
|
58
|
+
permissions:
|
|
59
|
+
id-token: write
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/download-artifact@v4
|
|
62
|
+
with:
|
|
63
|
+
name: dist
|
|
64
|
+
path: dist/
|
|
65
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 pytest-filemon developers
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pytest-filemon
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: File-level test impact analysis for pytest: per-test import dependencies recorded by wrapping __import__ (cached imports included), stored as local JSON, selected by file fingerprints.
|
|
5
|
+
Project-URL: Homepage, https://github.com/gnufede/pytest-filemon
|
|
6
|
+
Project-URL: Repository, https://github.com/gnufede/pytest-filemon
|
|
7
|
+
Project-URL: Issues, https://github.com/gnufede/pytest-filemon/issues
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Framework :: Pytest
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
19
|
+
Classifier: Topic :: Software Development :: Testing
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Requires-Dist: pytest>=7.4
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# pytest-filemon
|
|
25
|
+
|
|
26
|
+
**File-level test impact analysis (TIA)** for pytest — Filemón, the file-level
|
|
27
|
+
partner of [pytest-mortadelo](https://github.com/gnufede/pytest-mortadelo)
|
|
28
|
+
(block-level). Both work for the T.I.A. — here: Test Impact Analysis.
|
|
29
|
+
|
|
30
|
+
| | pytest-filemon |
|
|
31
|
+
|---|---|
|
|
32
|
+
| dependency storage | local JSON under `.pytest_filemon/` (not versioned; copy the directory to share it) |
|
|
33
|
+
| dependency unit | **whole files**: any change to a dependency file re-runs its dependents |
|
|
34
|
+
| dependency collection | wraps `builtins.__import__` and `importlib.import_module` — **every import statement, cached imports included**; no code instrumentation |
|
|
35
|
+
| import-time dependencies | everything imported before tests start is a dependency of *every* test; modules imported before arming are claimed, and their ASTs backfilled as possible dependencies |
|
|
36
|
+
| change detection | **file fingerprints** (size, mtime, content hash) — git only for new-file questions; `git diff` is the fallback |
|
|
37
|
+
| Python support | **3.9+** — no `sys.monitoring`, no bytecode analysis; anything that runs pytest |
|
|
38
|
+
|
|
39
|
+
Requires a git repository.
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install pytest-filemon
|
|
45
|
+
|
|
46
|
+
pytest --filemon # first run: everything runs, dependencies are recorded
|
|
47
|
+
pytest --filemon # second run: only tests whose dependency files changed
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Options:
|
|
51
|
+
|
|
52
|
+
| option | effect |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `--filemon` | enable recording + selection |
|
|
55
|
+
| `--filemon-force` | run all tests, but still record dependencies |
|
|
56
|
+
| `--filemon-clean` | discard the stored data before running |
|
|
57
|
+
| `PYTEST_FILEMON=1` | same as `--filemon` (env form; also enables before conftest loading) |
|
|
58
|
+
| `-p no:filemon` | disable the plugin entirely |
|
|
59
|
+
|
|
60
|
+
If nothing changed and nothing failed, **zero tests run and pytest exits
|
|
61
|
+
with code 0**: deselecting everything is a successful selection, not an
|
|
62
|
+
error. (A genuinely empty collection keeps pytest's own exit code 5.)
|
|
63
|
+
|
|
64
|
+
## How it works
|
|
65
|
+
|
|
66
|
+
### The import wraps
|
|
67
|
+
|
|
68
|
+
The recorder wraps `builtins.__import__` — the single choke point every
|
|
69
|
+
`import` and `from ... import ...` statement runs through, **hit or miss**
|
|
70
|
+
— and `importlib.import_module`. Each executed statement is resolved to
|
|
71
|
+
the repository files it names (the imported module, and its parent
|
|
72
|
+
packages, which execute at import too) and recorded as a dependency of
|
|
73
|
+
whatever is running:
|
|
74
|
+
|
|
75
|
+
- **import phase** (before collection: pytest plugins, conftest imports)
|
|
76
|
+
→ dependencies of *every* test. Modules already imported at arming
|
|
77
|
+
time have no statements left to see, so they are claimed from
|
|
78
|
+
`sys.modules`, and their full ASTs are backfilled: every import
|
|
79
|
+
statement in them — including dead branches — whose target is present
|
|
80
|
+
in `sys.modules` becomes a dependency. Backfill deliberately
|
|
81
|
+
over-approximates what ran before the recorder existed.
|
|
82
|
+
- **collect phase** (test module imports) → a test module's own imports
|
|
83
|
+
belong to its tests; a test module imported by pytest's machinery is a
|
|
84
|
+
dependency of its own tests; everything else is shared by every test.
|
|
85
|
+
- **test phase** → attributed to the running test's node id.
|
|
86
|
+
|
|
87
|
+
The wraps see **cached** imports — an import that hits `sys.modules`
|
|
88
|
+
fires no code event anywhere, but the statement still runs through
|
|
89
|
+
`__import__`, which is what makes whole-file dependencies complete
|
|
90
|
+
without any instrumentation: to call into a module, a test must execute
|
|
91
|
+
an import statement for it. This is also why filemon needs none of
|
|
92
|
+
mortadelo's extra machinery (the bytecode import scan, the fixture
|
|
93
|
+
closure, the `lru_cache` wrap): at file granularity, the plain import
|
|
94
|
+
edges subsume all three.
|
|
95
|
+
|
|
96
|
+
**Subprocess boundaries (always on):** the functions that create
|
|
97
|
+
processes are wrapped (`subprocess.Popen`, `os.system`,
|
|
98
|
+
`os.fork`/`posix_spawn`/`exec*`, `_posixsubprocess.fork_exec` — which
|
|
99
|
+
also covers `multiprocessing`). Coverage cannot follow a child
|
|
100
|
+
process, so when a test spawns one the recorder **stops collecting for
|
|
101
|
+
that test, writes no dependencies for it, and lists it in the data's
|
|
102
|
+
`always` key: it re-runs whenever anything changed** (reported as `N
|
|
103
|
+
always re-run (spawn subprocesses)`); a rerun with *provably nothing
|
|
104
|
+
changed* skips them like everything else via the no-change fast path.
|
|
105
|
+
|
|
106
|
+
The active configuration file (`pytest.ini` / `pyproject.toml` / ...)
|
|
107
|
+
is claimed as a shared dependency: a config change selects everything.
|
|
108
|
+
|
|
109
|
+
### Storage and selection
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
.pytest_filemon/
|
|
113
|
+
├── data.json {"version":1, "files":[...], "tests":{nodeid:[file-index...]}, "import_deps":[...], "failed":[...], "always":[...]}
|
|
114
|
+
├── meta.json {"version":1, "base_commit":..., "created":..., "failed":[...], "nodeids":[...], "dep_files":[...]}
|
|
115
|
+
└── files.json {"v":1, "at":ns, "files":{file:[size, mtime_ns, hash]}, "dirs":{dir:[subdirs]}}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
One dataset for the whole repository; each file replaced atomically. The
|
|
119
|
+
change detection (fingerprints: stat first, hash on doubt, racy-mtime
|
|
120
|
+
protection, new-file detection through one scoped `git ls-files`) is
|
|
121
|
+
shared code with pytest-mortadelo — see its README for the details.
|
|
122
|
+
|
|
123
|
+
A test runs when it has no recorded data (new), failed in the recorded
|
|
124
|
+
run, one of its dependency files is in `changed`, a shared import-time
|
|
125
|
+
dependency changed, or it is a spawner and anything changed. Selectors
|
|
126
|
+
(`-k`, `-m`, `--lf`, explicit `file.py::test` arguments) disable
|
|
127
|
+
selection entirely: an explicitly requested but unaffected test must
|
|
128
|
+
never be silently skipped.
|
|
129
|
+
|
|
130
|
+
## File granularity, honestly
|
|
131
|
+
|
|
132
|
+
Filemon re-runs *every* dependent of a changed file, even for a one-line
|
|
133
|
+
edit in a branch the test never touched — that is the trade: no
|
|
134
|
+
instrumentation, any Python, tiny overhead. What it does **not** see:
|
|
135
|
+
|
|
136
|
+
- **Stored / dynamic code paths**: a test only depends on files it (or
|
|
137
|
+
its module at collection, or a conftest in its chain) *imports*. A
|
|
138
|
+
test that calls `stored_functions[0]()` — a function defined in
|
|
139
|
+
`lib.py` and appended to a list at import time — records a dependency
|
|
140
|
+
on `lib.py` only if that import happened in its own chain. When the
|
|
141
|
+
list was filled by *another test module's* import, the edge belongs to
|
|
142
|
+
that module's tests alone and this test records nothing: edit
|
|
143
|
+
`lib.py`, and this test is silently skipped.
|
|
144
|
+
- **`.so` artifacts are files too**: `import fast` resolves the
|
|
145
|
+
extension module's path — a rebuild re-runs its importers. `ctypes`
|
|
146
|
+
dlopen without an import statement is not seen (mortadelo's world had
|
|
147
|
+
the same limit).
|
|
148
|
+
- **Data files** (fixtures, configs beyond the active pytest ini): not
|
|
149
|
+
dependencies — nothing executes them.
|
|
150
|
+
- **Backfill is an over-approximation**: before the recorder armed,
|
|
151
|
+
imports in dead branches of already-loaded modules count as
|
|
152
|
+
dependencies once their target is in `sys.modules`. Post-arm events
|
|
153
|
+
record only executed statements.
|
|
154
|
+
- **State-dispatched tests** (env vars, the clock, randomness): the
|
|
155
|
+
fundamental limit of any TIA.
|
|
156
|
+
|
|
157
|
+
For block-level precision (function/class granularity, stale-block
|
|
158
|
+
intersection, module skeletons), use
|
|
159
|
+
[pytest-mortadelo](https://github.com/gnufede/pytest-mortadelo).
|
|
160
|
+
|
|
161
|
+
## Development
|
|
162
|
+
|
|
163
|
+
The repo is managed with [uv](https://docs.astral.sh/uv/):
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
uv sync # create/update .venv from uv.lock (dev tools included)
|
|
167
|
+
uv run pytest # run the test suite (syncs automatically if needed)
|
|
168
|
+
uv run ruff check src tests
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The test suite uses `pytester` subprocess runs against real git
|
|
172
|
+
repositories, so it needs network-free local git only.
|
|
173
|
+
|
|
174
|
+
### Live demo
|
|
175
|
+
|
|
176
|
+
`demo/sqlalchemy_demo.py` runs a live overhead + edit→deselect benchmark
|
|
177
|
+
against sqlalchemy's ORM suite (2,480 tests over 12 files), with only
|
|
178
|
+
comment or no-op edits — nothing breaks, everything is restored:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
python3 demo/sqlalchemy_demo.py [path-to-sqlalchemy-checkout]
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
If the checkout has no `.venv*` virtualenv, the demo creates
|
|
185
|
+
`<checkout>/.venv` and installs sqlalchemy, pytest and this plugin
|
|
186
|
+
editable into it. Set `SQLALCHEMY_PYTHON` to use an existing interpreter.
|
|
187
|
+
|
|
188
|
+
Pytest output is streamed live, each edit is shown as a colored
|
|
189
|
+
`git diff`, and the demo waits for Enter between steps, so it can be
|
|
190
|
+
driven as a live walkthrough.
|
|
191
|
+
|
|
192
|
+
It shows the record overhead, the no-change fast path (0 tests, exit 0,
|
|
193
|
+
under a second), and where the deselect boundary sits — see the script
|
|
194
|
+
header for details.
|
|
195
|
+
|
|
196
|
+
## Layout
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
src/pytest_filemon/
|
|
200
|
+
├── plugin.py # pytest hooks, lifecycle, options
|
|
201
|
+
├── imports.py # the import wraps: __import__ / import_module + backfill
|
|
202
|
+
├── fingerprint.py # [size, mtime_ns, hash] snapshots and change detection
|
|
203
|
+
├── selection.py # stored-data parsing + test selection
|
|
204
|
+
├── store.py # .pytest_filemon/ JSON storage
|
|
205
|
+
└── util.py # path normalization
|
|
206
|
+
```
|