Skip tests that need netCDF4 or h5py instead of failing when they aren't installed - #1087
Draft
TomNicholas wants to merge 2 commits into
Draft
Skip tests that need netCDF4 or h5py instead of failing when they aren't installed#1087TomNicholas wants to merge 2 commits into
TomNicholas wants to merge 2 commits into
Conversation
netCDF4 is only ever used to write test files, and to read the tutorial datasets xarray fetches; nothing under test needs it at runtime. It was nonetheless imported unconditionally at the top of virtualizarr/tests/test_parsers/conftest.py, so without it the suite failed at collection rather than skipping. Add a netcdf4_lib fixture that calls pytest.importorskip, have every fixture that writes a netCDF file depend on it, and mark the handful of tests that write or read netCDF files in their own bodies with requires_netcdf4. With netCDF4 installed the suite is unchanged at 649 passed / 25 skipped. With it made unimportable at interpreter startup, the suite now reports 516 passed / 166 skipped with no failures or errors, where it previously reported 54 failures and 74 errors. Every CI environment installs netcdf4 through the hdf5-lib feature, so coverage there is unaffected.
Same treatment as netCDF4 in the previous commit. h5py is used only to write the HDF5 test files, and HDFParser reaches it through a soft import, but it was imported unconditionally at the top of two conftests and two test modules, so without it the suite failed at collection. Add an h5py_lib fixture calling pytest.importorskip and route the 29 fixtures that write HDF5 files through it; use a module-level importorskip in the two test modules that call h5py directly; and mark the tests that exercise HDFParser with requires_h5py, since the parser needs h5py at runtime even when the file was written by something else. The string_dtype_hdf5_url fixture is now parametrized by name rather than by value, because its parameter list called h5py.string_dtype() at import time, which cannot be deferred to a fixture. Suite totals, unchanged with everything installed and now clean without: all installed 649 passed, 25 skipped, 0 failed no netCDF4 516 passed, 166 skipped, 0 failed no h5py 484 passed, 135 skipped, 0 failed neither 446 passed, 174 skipped, 0 failed
TomNicholas
temporarily deployed
to
test-release
August 14, 2026 13:45 — with
GitHub Actions
Inactive
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1087 +/- ##
=======================================
Coverage 89.67% 89.67%
=======================================
Files 41 41
Lines 2682 2682
=======================================
Hits 2405 2405
Misses 277 277 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
netCDF4andh5pyare only needed to write the test files — and, for netCDF4, to read xarray's tutorial datasets. Nothing in the library requires them at import time. But both were imported unconditionally at the top of two conftests and two test modules, so without either the suite failed at collection rather than skipping.Changes
netcdf4_libandh5py_libfixtures callingpytest.importorskip, which the file-writing fixtures now depend on (2 in the root conftest, 29 intest_parsers/conftest.py).pytest.importorskipintest_hdf.pyandtest_hdf_filters.py, which callh5pydirectly.requires_netcdf4/requires_h5pymarkers on tests that read or write these files in their own bodies. That includes everything exercisingHDFParser, which needsh5pyat runtime via its soft import even when the file was written by netCDF4.string_dtype_hdf5_urlis parametrized by name rather than by value: itsparams=[...]calledh5py.string_dtype()at collection time, which no fixture can defer. Test IDs are unchanged.Suite totals
Every CI environment installs both through the
hdf5-libandhdffeatures, so coverage in CI is unchanged — the "all installed" row is the one CI exercises.Verified by blocking each library at interpreter startup via
sitecustomize.py, rather than from within a pytest plugin:virtualizarr.testsis imported beforepytest_configureruns, so a plugin-based block leaveshas_netcdf4already computed asTrueand the markers silently don't fire.