Skip to content

Commit

Permalink
Allow for fixture creation to be skipped (#345)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* adds a check to not bother creating a particular fixture if the `-m
"not requires_netcdf"` flag is set or if the files are missing.

### Does this PR introduce a breaking change?

No.

### Other information:

`pytest.mark` doesn't work for `pytest.fixture` objects. TIL
  • Loading branch information
Zeitsperre authored Feb 13, 2024
2 parents 877a027 + 278cc7f commit eea4ee7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Internal changes
* The OpenSSF `scorecard.yml` workflow has been added to the GitHub workflows to evaluate package security.
* Code formatting tools (`black`, `blackdoc`, `isort`) are now hard-pinned. These need to be kept in sync with changes from `pre-commit`. (Dependabot should perform this task automatically.)
* The versioning system has been updated to follow the Semantic Versioning 2.0.0 standard.
* Fixed an issue with `pytest -m "not requires_netcdf"` not working as expected. (:pull:`345`).

v0.8.0 (2024-01-16)
-------------------
Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ def remove_data_folder():
request.addfinalizer(remove_data_folder)


@pytest.mark.requires_netcdf
@pytest.fixture(scope="session")
def samplecat():
def samplecat(request):
"""Generate a sample catalog with the tutorial netCDFs."""
mark_skip = request.config.getoption("-m")
if "not requires_netcdf" in mark_skip or not SAMPLES_DIR.exists():
pytest.skip("Skipping tests that require netCDF files")
elif not list(SAMPLES_DIR.rglob("*.nc")):
pytest.skip("No netCDF files found in the tutorial samples folder")

df = xs.parse_directory(
directories=[SAMPLES_DIR],
patterns=[
Expand Down

0 comments on commit eea4ee7

Please sign in to comment.