Skip to content

Write HDF5 files of unit tests to tmp_path (Pytest fixture) - #205

Merged
yguclu merged 2 commits into
masterfrom
tests-use-tmp-path
Oct 30, 2026
Merged

yguclu merged 2 commits into
masterfrom
tests-use-tmp-path

Conversation

@yguclu

@yguclu yguclu commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Write the HDF5 files of the unit tests to the tmp_path fixture instead of the working directory, so that the tests can run in parallel without the xdist_group marker (fixes #204).

Problem

The six export/import tests of sympde/topology/tests/test_gallery.py all wrote and read the same file domain.h5 in the working directory. They relied on @pytest.mark.xdist_group('h5py') and --dist loadgroup to run one after another on the same worker.

pytest 9.2.0 (released 2026-10-27) changed how node IDs are stored, and pytest-xdist 3.8.0 can no longer assign tests to their group (see pytest-dev/pytest-xdist#1386, fixed in pytest-dev/pytest-xdist#1388 but not released yet). The grouped tests were therefore spread over the workers and failed randomly with BlockingIOError or OSError when two of them opened domain.h5 at the same time. This is what currently makes CI fail in #201.

Changes

  • Each test in test_gallery.py that exports a domain writes it to its own tmp_path, and the xdist_group('h5py') markers are removed.
  • test_topology_1 in test_topology.py writes omega.h5 to tmp_path too.
  • The removal of the output files in teardown_module is no longer needed and is deleted.
  • Remove --dist loadgroup from the pytest commands in CI and in the README, since no test uses the xdist_group marker anymore.
  • Add a [DEVELOPER] entry to the CHANGELOG.

Validation

With pytest 9.2.0 and pytest-xdist 3.8.0, pytest -n auto --dist loadgroup --pyargs sympde -ra passed 5 times in a row (180 passed, 2 skipped) and left no files in the working directory. On master, the same command failed in all 3 runs, with 2 or 3 failing tests each time. CI passes in all jobs with the final command pytest -n auto --pyargs sympde -ra.

The tests of test_gallery.py shared the file domain.h5 in the working
directory, and relied on the xdist_group marker to run on the same worker.
pytest 9.2.0 breaks this marker with pytest-xdist 3.8.0, so these tests ran
in parallel and failed randomly. Each test now writes to its own tmp_path,
and the marker is removed. The same is done for test_topology_1.
@yguclu yguclu self-assigned this Oct 29, 2026
@yguclu yguclu changed the title Write the HDF5 files of the unit tests to tmp_path Write HDF5 files of unit tests to tmp_path (Pytest fixture) Oct 29, 2026
No test uses the xdist_group marker anymore, so the default --dist load
scheduling of pytest-xdist is enough.

@kvrigor kvrigor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@yguclu

yguclu commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

lgtm!

Thanks for the review!

@yguclu
yguclu merged commit 8ca5a21 into master Oct 30, 2026
16 checks passed
@yguclu
yguclu deleted the tests-use-tmp-path branch October 30, 2026 10:18
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.

Gallery tests fail randomly with pytest 9.2.0

2 participants