pytest-randomly
Pytest plugin to randomly order tests and control random.seed.
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-randomlyuv
uv add pytest-randomlypoetry
poetry add pytest-randomlyInstalling 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
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-random-orderA pytest plugin that randomizes the order in…
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-find-dependenciesA pytest plugin that identifies dependencies…
permissive · top 5,000 on PyPI
random2Provides Python 2.7's random module…
permissive · top 15,000 on PyPI
pytest-orderA pytest plugin that lets you control the order…
permissive · top 5,000 on PyPI
pytest-orderingA pytest plugin that lets you control the…
permissive · top 5,000 on PyPI
pytest-isortA pytest plugin that automatically checks…
permissive · top 15,000 on PyPI
pytest-splitA pytest plugin that divides a test suite into…
permissive · top 5,000 on PyPI
pytest-replayA pytest plugin that records test execution…
permissive · top 15,000 on PyPI