Skip to content

Eighteen test modules build state at import: retire the collection-guard ratchet list #587

Open

Description

@lmoresi

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):

  • tests/test_0601_mesh_vector_calc.py

The rest build objects at import:

  • tests/parallel/test_0765_internal_boundary_integral_mpi.py
  • tests/test_0004_pointwise_fns.py
  • tests/test_0005_IndexSwarmVariable.py
  • tests/test_0501_integrals.py
  • tests/test_0502_boundary_integrals.py
  • tests/test_0504_projections.py
  • tests/test_0810_amr_swarm_migration_regression.py
  • tests/test_0830_mesh_adapt_variable_transfer.py
  • tests/test_1000_poissonCart.py
  • tests/test_1000_poissonNaturalBC.py
  • tests/test_1001_poissonSph.py
  • tests/test_1004_DarcyCartesian.py
  • tests/test_1010_stokesCart.py
  • tests/test_1011_stokesSph.py
  • tests/test_1014_stokes_multigrid.py
  • tests/test_1014_stokes_shell_nullspace.py
  • tests/test_1050_VEstokesCart.py

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

Activity

  1. lmoresi commented on Oct 5, 2026

    @lmoresi
    MemberAuthor

    Re-verified still live on development (1391e4aa), so the next session does not have to re-derive it: the ratchet in tests/conftest.py:117 still holds all 18 entries the title names, with test_0601_mesh_vector_calc.py — the one that moves units state at import, the #567 mechanism itself — still among them. Nothing has come off the list.

    Checked as part of the backlog sweep (#819); no fix here.

  2. lmoresi commented on Nov 13, 2026

    @lmoresi
    MemberAuthor

    Probe-pass verdict: still live on development 01dec8d. _KNOWN_COLLECTION_TIME_WORK in tests/conftest.py still holds all 18 entries, including test_0601_mesh_vector_calc.py, which moves the units state at import. Size M: 18 mechanical conversions to module-scoped fixtures, test_0601 first.

    Underworld development team with AI support from Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions