Skip to content

Generate the numba test module once per module - #930

Merged
garth-wells merged 1 commit into
mainfrom
garth/numba-test-module-scope
Oct 20, 2026
Merged

garth-wells merged 1 commit into
mainfrom
garth/numba-test-module-scope

Conversation

@garth-wells

Copy link
Copy Markdown
Member

Follow-up to #911, picking up the one part of @jhale's review on #923 that #911 did not carry over.

Background

#911 fixed the pytest-xdist race in test_numba.py by generating into a pytest temporary directory and loading via spec_from_file_location, rather than sharing ./poisson_numba.py across workers. That is the approach the review on #923 argued for, and it is what landed.

That review also used scope="module" with tmp_path_factory. #911 kept the fixture function-scoped, so the Poisson module is regenerated for each of the four parametrized tests.

Change

Make generate_poisson module-scoped. This requires tmp_path_factory, because the function-scoped tmp_path cannot be requested from a module-scoped fixture. Sharing one module instance is safe: the tests only read form_poisson_a / expression_poisson_0 and wrap them, never mutate the module.

Two related tidy-ups, both consequences of #911:

  • Drop poisson_numba.py from .gitignore. Nothing writes it to the source tree any more — the only reference is under the temporary directory.
  • Drop the stale mention of ffcx.main from the add_cwd_to_syspath docstring in test/conftest.py. The fixture is still needed and still autouse, but CFFI is now the only thing compiling into CWD.

Verification

Fixture setups, via pytest --setup-show:

setups
main 4
this PR 1

Serial wall clock for pytest test/test_numba.py: 1.68–2.18s on main, 1.57–1.68s here.

Passes serially, at -n 5 (5 consecutive runs), and when invoked from test/ rather than the project root. git status --untracked-files=all is clean after all of those, confirming the .gitignore removal is safe. test_jit_forms.py -k "laplace or helmholtz" passes, covering the CFFI path through the touched conftest.py. ruff check and ruff format --check are clean.

Scope note: the saving is serial-only. Under xdist the four tests scatter across workers, each with its own module scope, so the generation still runs four times — I instrumented the fixture and confirmed one run each on gw1–gw4 at -n 5. Since CI runs -n auto, this helps local runs and not CI.

Test-only; no library change.

🤖 Generated with Claude Code

Follow-up to #911, which fixed the xdist race by generating into a
pytest temporary directory but left the fixture function-scoped, so the
Poisson module was regenerated for each of the four parametrized tests.

Make the fixture module-scoped, which needs `tmp_path_factory` since the
function-scoped `tmp_path` cannot be requested from a module-scoped
fixture. Generation drops from 4 runs to 1 when run serially; under
xdist the tests scatter across workers, each with its own module scope,
so the count there is unchanged.

Also drop the now-dead `poisson_numba.py` from .gitignore and the stale
reference to `ffcx.main` in the `add_cwd_to_syspath` docstring: since
#911 nothing writes generated code into the working directory except
CFFI.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@garth-wells
garth-wells enabled auto-merge October 20, 2026 06:27
@garth-wells
garth-wells added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit 2b828b7 Oct 20, 2026
18 checks passed
@garth-wells
garth-wells deleted the garth/numba-test-module-scope branch October 20, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant