Skip to content

bug: marks on the mf6_gwf_2sp_st_tr fixture have no effect and break collection under pytest 9 #2798

Description

@jdhughes-dev

Describe the bug

autotest/test_binaryfile.py applies two marks to the mf6_gwf_2sp_st_tr fixture:

@pytest.fixture
@pytest.mark.mf6
@requires_exe("mf6")
def mf6_gwf_2sp_st_tr(function_tmpdir):

pytest has never honored marks on a fixture. Under pytest 8 this is a warning and the marks are silently dropped:

PytestRemovedIn9Warning: Marks applied to fixtures have no effect

Because requires_exe("mf6") is dropped, test_read_mf6_2sp (the only test that uses the fixture) is not skipped when mf6 is not installed. It fails instead:

FAILED autotest/test_binaryfile.py::test_read_mf6_2sp - FileNotFoundError: The program mf6 does not exist or is not executable.

Under pytest 9 the warning became an error, and it aborts collection of the whole module rather than the one test:

ERROR autotest/test_binaryfile.py - Failed: Marks cannot be applied to fixtures.
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!

To Reproduce

The dead guard is reproducible on the current pytest:

  1. Install flopy's test dependencies without the mf6 executable on PATH
  2. pytest autotest/test_binaryfile.py::test_read_mf6_2sp
  3. The test fails with FileNotFoundError rather than being skipped

The collection error needs pytest 9:

  1. pip install "pytest==9.1.1"
  2. pytest autotest/test_binaryfile.py --co
  3. Collection of all 46 tests in the module is aborted

Expected behavior

test_read_mf6_2sp should be skipped when mf6 is not installed, and test_binaryfile.py should collect on pytest 9.

Moving both marks from the fixture to test_read_mf6_2sp does this. With that change pytest 9.1.1 and pytest 8.4.2 produce identical results across the suite.

Additional context

flopy does not currently install pytest 9 — syrupy <5.0.0 resolves to syrupy 4.9.1, which requires pytest >=7.0.0,<9.0.0. flopy's own constraint is only pytest !=8.1.0, so relaxing the syrupy pin lets pytest 9 in and turns this into a collection failure. The dead requires_exe guard is present today regardless of the pytest version.

This is the only fixture in the repository with a mark applied to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions