skillfed

pytest-randomly

Pytest plugin to randomly order tests and control random.seed.

pytest-randomly v4.1.0 10.0M downloads/30d#1,491 on PyPI719
Permissive license MIT Active released

What it is and what it does

pytest-randomly is a pytest plugin that randomizes test execution order and manages random seeds to expose hidden test dependencies and ensure reproducible test behavior. By default, it shuffles tests at the module, class, and function levels, then resets Python's global random seed before each test to a deterministic value derived from a base seed, the test ID, and an offset. This allows tests that use random data (via factory boy, Faker, NumPy, or Model Bakery) to remain repeatable while still exercising different code paths across runs.

The plugin prints the base random seed at the start of each test run, allowing developers to reproduce failures caused by test ordering or random data by passing that seed back via the `--randomly-seed` flag. It integrates with pytest-xdist for distributed testing and supports custom random generators through an entry point mechanism. Behaviors can be disabled individually with flags like `--randomly-dont-reorganize` or `--randomly-dont-reset-seed`, and the plugin can be completely disabled with `-p no:randomly`.

Use it for:

  • Detect inter-test pollution by running tests in random order and reproducing failures with a saved seed.
  • Ensure factory-generated test data remains consistent across runs while varying between tests.
  • Verify that tests do not depend on global state or execution order from other tests.
  • Reproduce flaky test failures caused by random data or test ordering by rerunning with the reported seed.
  • Validate test quality by exposing assumptions about test isolation and data setup.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A pytest plugin that randomly shuffles test execution order and controls the random seed for each test, helping detect hidden test dependencies and ensuring reproducible randomized test data.

Yes. This is a mature, actively maintained plugin (Production/Stable status, recent release 2026-04-20) with low install friction and no security vulnerabilities. It solves a real testing problem—detecting hidden test dependencies—that can catch subtle bugs. The MIT license imposes no restrictions. Install it if you want to improve test reliability and catch ordering-dependent failures early.

Install

pytest-randomly on PyPI

pip

pip install pytest-randomly

uv

uv add pytest-randomly

poetry

poetry add pytest-randomly

Installing pytest-randomly

Before you install

Low friction install with a single runtime dependency on pytest. Actively maintained with recent releases; the repository shows 719 stars and the last commit was 2026-08-13, indicating ongoing development.

License in practice

MIT license is permissive, allowing use in both open-source and proprietary projects with minimal restrictions.

Quickstart

pip install pytest-randomly

# Then run pytest normally; the plugin auto-activates:
pytest

# Output shows the random seed:
# Using --randomly-seed=1553614239

# Reproduce a failure with:
pytest --randomly-seed=1234

Requires Python 3.10 or later.

Verify before relying

  • Whether the plugin works reliably with all pytest-xdist configurations and distributed test scenarios
  • Performance impact when running large test suites with hundreds or thousands of tests

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pytest
Maintenance actively maintained — 116 days since the last release
Last repo commit
First released
Downloads 10,021,263/month — #1,491 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_randomly-4.1.0-py3-none-any.whl

Keywords: pytest, random, randomise, randomize, randomly

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersNatural Language :: EnglishProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Typing :: Typed

Tags

pytest random test ordertest randomization pluginrandom seed control pytestdetect test dependenciesreproducible random testsshuffle test executionpytest test ordering
test-qualityrandomizationpytest-plugin

More Testing packages