tests/conftest.py now fingerprints the process state around each test module's
import and fails the run when a module moves it (#575). Eighteen modules already
do, so they are exempted by name in _KNOWN_COLLECTION_TIME_WORK — a ratchet
that stops the practice spreading, not an approval of it. This issue is the list.
Why module-level work is not merely untidy
pytest imports a module in order to collect it, so anything at module level runs
before any test, any fixture, and any isolation conftest.py provides. Two
defects reached development that way:
A module that builds a mesh at import has not failed yet; it has built its mesh
under whatever global state the previously collected module left behind.
The list
Fix first, because it is the only one that moves the units state
(uw.use_strict_units(False) at line 28, before three meshes and fourteen
variables — the #567 mechanism exactly):
The rest build objects at import:
The fix, per module
Move the module-level objects into a scope="module" fixture and take it as an
argument. tests/test_0050_utils.py, test_0120_data_property_access.py and
test_0130_field_creation.py were converted this way in the same PR and are the
worked examples. Delete the entry from _KNOWN_COLLECTION_TIME_WORK in the same
commit — the guard then holds that module.
Adjacent
scripts/test.sh disables tests/test_06*py wholesale ("regression tests need
validation"), which is why test_0601's import-time units flip has never been
noticed by CI: it is collected by any whole-directory run but never executed by
ours. That is a coverage gap for #570.
Underworld development team with AI support from Claude Code
tests/conftest.pynow fingerprints the process state around each test module'simport and fails the run when a module moves it (#575). Eighteen modules already
do, so they are exempted by name in
_KNOWN_COLLECTION_TIME_WORK— a ratchetthat stops the practice spreading, not an approval of it. This issue is the list.
Why module-level work is not merely untidy
pytest imports a module in order to collect it, so anything at module level runs
before any test, any fixture, and any isolation
conftest.pyprovides. Twodefects reached
developmentthat way:module-scoped fixture in that worker built its mesh under dimensional
coordinates. Sampled 2.9 million times too far apart; it looked like a
parallelism bug and blocked CI parallelism for days.
--collect-onlysatinside
SNESSolvelooking like a silent death.A module that builds a mesh at import has not failed yet; it has built its mesh
under whatever global state the previously collected module left behind.
The list
Fix first, because it is the only one that moves the units state
(
uw.use_strict_units(False)at line 28, before three meshes and fourteenvariables — the #567 mechanism exactly):
tests/test_0601_mesh_vector_calc.pyThe rest build objects at import:
tests/parallel/test_0765_internal_boundary_integral_mpi.pytests/test_0004_pointwise_fns.pytests/test_0005_IndexSwarmVariable.pytests/test_0501_integrals.pytests/test_0502_boundary_integrals.pytests/test_0504_projections.pytests/test_0810_amr_swarm_migration_regression.pytests/test_0830_mesh_adapt_variable_transfer.pytests/test_1000_poissonCart.pytests/test_1000_poissonNaturalBC.pytests/test_1001_poissonSph.pytests/test_1004_DarcyCartesian.pytests/test_1010_stokesCart.pytests/test_1011_stokesSph.pytests/test_1014_stokes_multigrid.pytests/test_1014_stokes_shell_nullspace.pytests/test_1050_VEstokesCart.pyThe fix, per module
Move the module-level objects into a
scope="module"fixture and take it as anargument.
tests/test_0050_utils.py,test_0120_data_property_access.pyandtest_0130_field_creation.pywere converted this way in the same PR and are theworked examples. Delete the entry from
_KNOWN_COLLECTION_TIME_WORKin the samecommit — the guard then holds that module.
Adjacent
scripts/test.shdisablestests/test_06*pywholesale ("regression tests needvalidation"), which is why
test_0601's import-time units flip has never beennoticed by CI: it is collected by any whole-directory run but never executed by
ours. That is a coverage gap for #570.
Underworld development team with AI support from Claude Code