@@ -122,12 +122,6 @@ Full examples (a function, a test, module and class docstrings): [docs/developer
122122
123123Every test follows Arrange-Act-Assert, with ` # Arrange ` , ` # Act ` and ` # Assert ` comments.
124124
125- Always cover:
126- 1 . ** Normal cases** — typical inputs.
127- 2 . ** Edge cases** — empty inputs, single items, max values.
128- 3 . ** Error cases** — invalid inputs, type errors.
129- 4 . ** Integration** — components working together.
130-
131125Naming: ` test_<function_name>_<scenario>_<expected_outcome> ` , ** kept under 60
132126characters** . Omit any part the module or class name already carries — a test in
133127` test_config.py ` needs no ` config_ ` prefix — and drop ` _returns_* ` tails when the
@@ -145,72 +139,10 @@ test_init_strain_without_filenames_raises
145139
146140### Test tiers, markers, and locations
147141
148- Tests are split into four tiers so the fast ones can be run without waiting on
149- real data, a full ring calibration, or GUI pop-ups. ** Put every new test in the tier
150- matching what it actually touches, and apply the marker that tier requires.**
151-
152- | Tier | Location | Marker | Run with |
153- | ---| ---| ---| ---|
154- | Unit | ` tests/unit/<module-path>/ ` , mirroring the ` pyrs/ ` package layout | * none* | ` pixi run test-unit ` |
155- | Ring calibration | ` tests/unit/<module-path>/ ` , beside the unit tests | ` @pytest.mark.ring_calibration ` | ` pixi run test-ring-calibration ` |
156- | Integration | ` tests/integration/ ` (flat) | ` @pytest.mark.integration ` | ` pixi run test-integration ` |
157- | GUI | ` tests/ui/ ` | ` @pytest.mark.gui ` ** and** ` @pytest.mark.integration ` | ` pixi run test-gui ` |
158- | By-hand scripts | ` tests/scripts/ ` | * n/a — never collected* | run the file directly |
159-
160- Marker definitions, registered in ` pyproject.toml ` :
161-
162- - ** ` integration ` ** — exercises real file I/O (` tests/data ` , the ` /HFIR `
163- archive) or a multi-component workflow.
164- - ** ` ring_calibration ` ** — runs a full ring calibration of the synthetic run, or
165- uses the shared one (` tests/util/ring_calibration_helpers.py ` :
166- ` converged_synthetic_calibration ` , ` use_cached_calibrate_rings ` ). That
167- calibration takes ~ 30 s and is cached per process, so the tier runs serially
168- and computes it once; in the parallel unit tier every worker would compute it
169- again (#1101 ).
170- - ** ` gui ` ** — requires a display (xvfb or offscreen). Constructing or driving a
171- Qt widget is the usual reason, but it is not the only one: taking the ` qapp `
172- fixture is enough on its own (it builds a real ` QApplication ` , which aborts
173- with no display), as is importing any module that pulls in matplotlib's
174- ` QtAgg ` backend at module scope. If the module cannot be * imported* headless,
175- it is ` gui ` — ` python -c 'import <module>' ` with ` DISPLAY ` and
176- ` QT_QPA_PLATFORM ` unset is the check.
177-
178- Notes:
179-
180- - Markers are enforced by ` addopts = "--strict-markers" ` : an unregistered marker
181- is an error, not a silent no-op. Register new markers in ` pyproject.toml ` .
182- - ` test-gui ` selects ` -m gui ` ; ` test-integration ` selects
183- ` -m 'integration and not gui' ` . GUI tests therefore carry ** both** markers —
184- ` gui ` alone would drop them from the integration tier.
185- - A test is a * unit* test only if it needs no real file and no widget. If it
186- loads a fixture file purely for convenience, prefer rewriting it against a
187- synthetic fixture and keeping it in the unit tier.
188- - Apply a whole-module marker with ` pytestmark = pytest.mark.integration ` rather
189- than decorating every function.
190- - ` tests/util/ ` holds shared helper modules and fixtures, not tests of its own
191- (beyond tests * for* those helpers); ` tests/scripts/ ` is excluded from
192- collection via ` norecursedirs ` .
193- - ` test-gui ` sets ` QT_QPA_PLATFORM=offscreen ` itself, so no window ever appears.
194- The full ` pixi run test ` (all tiers, serial, with coverage) does ** not** . Export
195- ` QT_QPA_PLATFORM=offscreen ` yourself before running it on a workstation with a
196- real desktop session, or it will stall on the GUI tier until the timeout below
197- fires — see [ docs/ground_truths.md] ( docs/ground_truths.md ) .
198- - ** The unit and integration tiers run in parallel** (` pytest-xdist ` , `-n auto
199- --dist loadscope`: one worker per core, at most 8 locally; a module's top-level test functions, or a
200- test class, all go to one worker, so a module-scoped fixture used by functions is
201- built once). The GUI tier stays serial: its tests share one window per module.
202- So a test must not depend on another test's order or write a fixed file name
203- into the working folder; use ` tmp_path ` . To debug with ` --pdb ` or ` -s ` , run
204- serially: ` pixi run test-unit -n 0 ` . The ring-calibration tier is serial (see its marker). CI runs
205- each tier as its own job (` test-ci-unit ` , ` test-ci-ring-calibration ` , ` test-ci-integration ` ,
206- ` test-ci-gui ` , under ` xvfb-run ` , #1100 , #1101 ).
207- - ** Every test has a 300-second timeout** (` timeout ` /` timeout_method ` in
208- ` pyproject.toml ` , via ` pytest-timeout ` ). A hang is a failure, not an infinite
209- wait. ` timeout_method = "thread" ` is deliberate: a test blocked inside Qt's C++
210- event loop never returns to the interpreter, so the default ` signal ` method
211- cannot interrupt it — verified. The watchdog dumps every thread's stack, which
212- names the blocking line. Override per-test with ` @pytest.mark.timeout(N) ` for a
213- genuinely long-running case rather than raising the global limit.
142+ Put every new test in the tier matching what it touches (unit, ring calibration, integration, GUI)
143+ and apply that tier's marker. ** Read [ tests/CLAUDE.md] ( tests/CLAUDE.md ) before adding a test** : it
144+ holds the tier table, marker rules, parallel-run rules and timeout policy, and loads when you work
145+ under ` tests/ ` .
214146
215147<!-- cherry-pick 30231c18: BEGIN added block "Pytest markers" -->
216148** Pytest markers** — apply the correct marker(s) when a test is * written* ,
0 commit comments