Ouranosinc / xscen

A climate change scenario-building analysis framework.
https://xscen.readthedocs.io/
Apache License 2.0
15 stars 2 forks source link

`pytest --mark` not working as intended #344

Closed Zeitsperre closed 7 months ago

Zeitsperre commented 7 months ago

Setup Information

Description

When trying to run a subset of the tests using pytest tests -m "not requires_netcdf", the command fails due to the fact that there are pytest.fixture objects in the conftest.py that require these missing files to exist. Marking a pytest.fixture does not skip the creation of fixtures, unfortunately.

We may need to add a pytest.skipif(...) call within the affected fixture.

Steps To Reproduce

$ pytest tests -m "not requires_netcdf"

Gives:


==================================== ERRORS ====================================
______________________ ERROR at setup of test_build_path _______________________

    @pytest.mark.requires_netcdf
    @pytest.fixture(scope="session")
    def samplecat():
        """Generate a sample catalog with the tutorial netCDFs."""
>       df = xs.parse_directory(
            directories=[SAMPLES_DIR],
            patterns=[
                "{activity}/{domain}/{institution}/{source}/{experiment}/{member}/{frequency}/{?:_}.nc"
            ],
            homogenous_info={
                "mip_era": "CMIP6",
                "type": "simulation",
                "processing_level": "raw",
            },
            read_from_file=["variable", "date_start", "date_end"],
            xr_open_kwargs={"engine": "h5netcdf"},
        )

tests/conftest.py:33: 

...

=========================== short test summary info ============================
ERROR tests/test_catutils.py::test_build_path - ValueError: No files found.
ERROR tests/test_catutils.py::test_build_path_multivar - ValueError: No files found.
ERROR tests/test_ensembles.py::TestEnsemblePartition::test_build_partition_data - ValueError: No files found.
ERROR tests/test_extract.py::TestSearchDataCatalogs::test_input_types - ValueError: No files found.
========= 232 passed, 8 deselected, 1040 warnings, 4 errors in 37.81s ==========

Additional context

https://stackoverflow.com/questions/46852934/is-there-a-way-to-skip-a-pytest-fixture

Contribution