Marker Application Behavior
There are no fundamental changes in how pytest 8.0 applies custom markers to test items compared to pytest 7.6 when running under Python 3.12. The core mechanism of attaching markers via decorators remains consistent across these versions and interpreters. However, the visibility and reporting of these markers have evolved, which can create the appearance of divergence in CI/CD pipelines or CLI output.
Likely Explanations for Observed Divergence
If you observe differences in marker behavior between pytest 7.6 and 8.0, they are likely caused by the following changes in configuration discovery and validation rather than the application logic itself:
- Configuration Source: Pytest 8.0 places heavier emphasis on
pyproject.toml. Markers defined in [tool.pytest.markers] are now more prominently surfaced via the --markers flag. If markers were previously registered only via conftest.py without corresponding entries in the configuration file, pytest 8.0 may trigger "unknown marker" warnings that were less aggressive in 7.6.
- Error Reporting: Pytest 8.0 includes improved error messaging for missing or unregistered markers. This may surface existing configuration gaps that were previously silent in pytest 7.6.
- Python 3.12 Type Handling: While the pytest marker application is unchanged, Python 3.12's stricter handling of type annotations may cause static analysis tools (like Mypy or Pyright) to flag marker arguments differently, though this does not affect runtime execution.
Verification and Compatibility Steps
To ensure compatibility and consistency across pytest 7.6 and 8.0 on Python 3.12, follow these steps:
- Centralize Marker Definitions: Move or duplicate custom marker registrations into
pyproject.toml to ensure they are recognized by the pytest 8.0 discovery engine:
[tool.pytest.markers]
my_custom_marker = "description of marker"
- Verify Discovery: Run the following command to confirm that all intended markers are recognized by the current version:
pytest --markers
- Audit Plugin Hooks: Ensure that any plugins modifying markers via
pytest_collection_modifyitems are not relying on internal pytest 7.x APIs that may have been deprecated in 8.0.
Diagnostic Requirement: To provide a more specific recommendation, please clarify if the "difference" is a runtime failure (e.g., tests not being filtered) or a configuration warning (e.g., PytestUnknownMarkWarning).