{"id":2235,"library":"pytest-order","title":"Pytest Order Plugin","description":"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.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-order","tags":["pytest","testing","test-runner","order"],"install":[{"cmd":"pip install pytest-order","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"This is a pytest plugin and requires pytest to function.","package":"pytest","optional":false}],"imports":[{"note":"pytest-order operates via pytest markers. Direct Python imports from the plugin are generally not used in user code.","symbol":"pytest.mark.order","correct":"import pytest\n\n@pytest.mark.order(1)"}],"quickstart":{"code":"import pytest\n\n@pytest.mark.order(1)\ndef test_first():\n    assert True\n\n@pytest.mark.order(2)\ndef test_second():\n    assert True\n\n@pytest.mark.run(after='test_first')\ndef test_dependency_on_first():\n    assert True\n\n@pytest.mark.run(before='test_second')\ndef test_dependency_before_second():\n    assert True\n\n# To run these tests:\n# 1. Save the code as a Python file (e.g., test_ordering.py)\n# 2. Run from your terminal: pytest test_ordering.py","lang":"python","description":"Demonstrates basic test ordering using `@pytest.mark.order` and dependency-based ordering using `@pytest.mark.run(after='...')` and `@pytest.mark.run(before='...')`."},"warnings":[{"fix":"Upgrade to Python 3.7+ or pin pytest-order to a version <=0.11.0.","message":"Python 2.7 support was dropped in version 1.0.0. Users requiring Python 2.7 compatibility must stick to pytest-order v0.11.0 or older.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"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.","message":"Using pytest-order with `pytest-xdist` can lead to unpredictable test execution order, as `pytest-xdist` parallelizes tests across processes, potentially breaking assumed sequential order.","severity":"gotcha","affected_versions":"All"},{"fix":"Use dependency markers (`@pytest.mark.run`) for cross-scope ordering, or enable `--hierarchical-ordering` and carefully define order across directories/modules.","message":"By default, `@pytest.mark.order` applies within its declared scope (module, class). Cross-module or cross-class ordering often requires explicit `@pytest.mark.run(after='...')` markers or the `--hierarchical-ordering` option.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"Version 1.3.0 introduced the `--error-on-failed-ordering` option. Previously, tests whose order could not be resolved would simply run without an enforced order. With this flag, such tests will now fail, changing default behavior if the flag is enabled.","severity":"gotcha","affected_versions":">=1.3.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}