skillfed

pytest-random-order

Randomise the order in which pytest tests are run with some control over the randomness

pytest-random-order v1.2.0 2.8M downloads/30d#2,864 on PyPI79
Permissive license MIT Active released

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-order

uv

uv add pytest-random-order

poetry

poetry add pytest-random-order

Installing 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

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Topic :: Software Development :: Testing

Tags

pytest test order randomizationdetect test dependenciespytest shuffle teststest isolation verificationpytest random seed reproducible
test-qualitypytest-plugin

More Testing packages