pytest-order is a pytest plugin that allows running tests in a specific, user-defined order. It integrates with pytest using markers, providing various levels of control including custom order, dependency-based ordering, and relative ordering. The current version is 1.3.0, and it maintains an active release cadence with regular updates.
pip install pytest-orderVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic test ordering using `@pytest.mark.order` and dependency-based ordering using `@pytest.mark.run(after='...')` and `@pytest.mark.run(before='...')`.
Upgrade to Python 3.7+ or pin pytest-order to a version <=0.11.0.
Avoid using `pytest-xdist` for tests where explicit ordering is critical, or use `pytest --dist=no` to disable parallelization for specific runs. Ensure dependencies are only within tests executed in the same process.
Use dependency markers (`@pytest.mark.run`) for cross-scope ordering, or enable `--hierarchical-ordering` and carefully define order across directories/modules.
Be aware of this option's behavior. If you prefer tests to run unordered rather than fail, ensure `--error-on-failed-ordering` is not enabled, or adjust your ordering markers to resolve all dependencies.