pytest-random-order
Randomise the order in which pytest tests are run with some control over the randomness
What it is and what it does
pytest-random-order is a pytest plugin that shuffles the order in which tests execute, with fine-grained control over randomization scope. By default it does not randomize; you opt in via command-line flag or configuration. The plugin groups tests into buckets (by class, module, package, or globally) and shuffles within and across buckets, allowing you to detect tests that pass only because they run after another test that leaves the system in a particular state—a common source of hidden test fragility.
The plugin reports the random seed used in each run, so if a specific test order reveals a failure, you can reproduce it exactly by passing that seed back. It also supports disabling randomization for specific modules or classes, respects pytest's failed-first flag, and can be disabled entirely if needed. It integrates seamlessly as a pytest plugin with no external dependencies beyond pytest itself.
Use it for:
- Detect tests that depend on execution order or shared state by running them in random order and catching failures that don't occur in default order.
- Reproduce a specific test failure by rerunning with the seed value reported in the original test output.
- Verify test isolation at module or package scope before moving to more aggressive global randomization.
- Disable randomization for known-fragile test classes while randomizing the rest of the suite.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that randomizes the order in which tests run, helping detect test interdependencies and order-dependent failures.
Yes. This is a lightweight, actively maintained plugin with zero security issues and a clear, narrow purpose: catching test order dependencies. Install it if you want to harden your test suite against hidden interdependencies. The opt-in design means it won't affect existing test runs unless you explicitly enable it.
Install
pytest-random-order on PyPI
pip
pip install pytest-random-orderuv
uv add pytest-random-orderpoetry
poetry add pytest-random-orderInstalling pytest-random-order
Before you install
Low friction: pure Python wheel with only pytest as a runtime dependency. Actively maintained with recent commits and stable production status.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions.
Quickstart
pip install pytest-random-order
# In pytest.ini or pyproject.toml:
# [pytest]
# addopts = --random-order
# Or run: pytest --random-order
Requires Python 3.9 or later.
Verify before relying
- Whether the plugin's bucket types (class, module, package, global, etc.) cover all real-world test organization patterns users encounter.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | actively maintained — 418 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,844,743/month — #2,864 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_random_order-1.2.0-py3-none-any.whl
Keywords: pytest, random, test, order, shuffle
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-randomlyA pytest plugin that randomly shuffles test…
permissive · top 5,000 on PyPI
pytest-reverseA pytest plugin that runs tests in reverse…
permissive · top 15,000 on PyPI
pytest-rngProvides pytest fixtures that make random…
permissive · top 15,000 on PyPI
pytest-splitA pytest plugin that divides a test suite into…
permissive · top 5,000 on PyPI
pytest-isortA pytest plugin that automatically checks…
permissive · top 15,000 on PyPI
random2Provides Python 2.7's random module…
permissive · top 15,000 on PyPI
pytest-retrypytest-retry is a pytest plugin that…
permissive · top 5,000 on PyPI
pytest-orderingA pytest plugin that lets you control the…
permissive · top 5,000 on PyPI
flakyA pytest plugin that automatically reruns…
permissive · top 5,000 on PyPI
pytest-rerunfailuresA pytest plugin that automatically reruns…
copyleft · top 1,000 on PyPI