pytest-reverse
raw JSON → 1.9.0 verified Fri May 01 auth: no python
A pytest plugin that reverses the order of test execution. Useful for detecting tests that accidentally depend on order or for randomization. Current version 1.9.0, compatible with Python >=3.9.
pip install pytest-reverse Common errors
error AttributeError: module 'pytest' has no attribute 'mark' ↓
cause Forgetting to import pytest before using the marker.
fix
Add 'import pytest' at the top of your test file.
error Unknown pytest.mark.reverse - did you mean 'pytest.mark.skip' ↓
cause pytest-reverse is not installed.
fix
Install with 'pip install pytest-reverse'.
error WARNING: usage: pytest [options] [file_or_dir] error: unrecognized arguments: --reverse ↓
cause pytest-reverse is not installed or not registered as a plugin.
fix
Install with 'pip install pytest-reverse' and ensure you're running pytest in the correct environment.
Warnings
gotcha The --reverse flag reverses the order of tests within each scope (module, class, function). It does NOT reverse the order of test files unless combined with other plugins. ↓
fix To reverse test file order, use pytest --reverse --co (with pytest-order plugin) or sort test files manually.
gotcha Using @pytest.mark.reverse() at the class level reverses tests within that class, but does not reverse tests outside the class. ↓
fix Apply marker to each test function you want reversed, or use --reverse for global reversal.
deprecated The pytest.mark.reverse marker without parentheses (e.g., @pytest.mark.reverse) is deprecated since version 1.7.0 and will be removed in a future release. ↓
fix Use @pytest.mark.reverse() with parentheses.
Imports
- reverse
pytest.mark.reverse
Quickstart
# Run all tests in reverse order
pytest --reverse
# Reverse a single test with marker
import pytest
@pytest.mark.reverse()
def test_one():
assert True
def test_two():
assert True