pytest-ordering
pytest-ordering is a pytest plugin designed to enable users to run tests in a specific, user-defined order. The latest version is 0.6, released in 2018. This project is no longer maintained, and users are strongly advised to migrate to its successor, `pytest-order`, which provides active development and additional features.
Warnings
- breaking The `pytest-ordering` project is no longer maintained. It is highly recommended to migrate to `pytest-order` for continued support and new features.
- breaking When migrating from `pytest-ordering` to `pytest-order`, the marker name changes from `run` to `order`. Using `pytest.mark.run` with `pytest-order` will not work.
- gotcha Relying on specific test execution order is generally considered a bad practice in testing, as it can indicate hidden dependencies between tests and lead to flaky tests. This plugin facilitates such ordering, but it's important to be aware of the potential downsides.
- gotcha Using `pytest-ordering` (or any ordering plugin) with other plugins that modify test execution order (e.g., `pytest-xdist`, `pytest-random-order`, `pytest-dependency`) can lead to unpredictable or overridden test orders due to plugin interaction and execution precedence.
Install
-
pip install pytest-ordering
Imports
- pytest.mark.run
import pytest @pytest.mark.run(order=1)
Quickstart
import pytest
def test_c():
assert True
@pytest.mark.run(order=2)
def test_foo():
assert True
@pytest.mark.run(order=1)
def test_bar():
assert True
# To run: pytest your_test_file.py -v
# Expected order: test_bar, test_foo, test_c (tests without explicit order might run last, or alphabetically among themselves)