pytest-rng
Fixtures for seeding tests and making randomness reproducible
What it is and what it does
pytest-rng is a pytest plugin that provides two fixtures—`rng` and `seed`—to make random number generation deterministic and reproducible in tests. The `rng` fixture returns a pre-seeded NumPy RandomState object, while the `seed` fixture provides an integer seed value. Both derive their seeds by hashing the test's node ID combined with an optional salt string, ensuring the same random sequence runs every time unless you explicitly change the salt to test robustness across different seeds.
The package depends on numpy and pytest. It was released once on August 8, 2019 and has not been updated since, making it a stable but unmaintained tool. It is most useful for test suites that need reproducible randomness—such as machine learning or numerical computing tests—where you want to verify that random variations don't mask real bugs, yet still want to change seeds periodically to catch seed-dependent failures.
Use it for:
- Ensure machine learning model tests produce identical results across runs for CI/CD pipelines
- Test numerical algorithms with reproducible random inputs while rotating seeds to catch fragile tests
- Verify stochastic simulations behave consistently without hardcoding seed values in test code
- Generate deterministic test data from random distributions without manual seed management
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides pytest fixtures that make random number generation reproducible across test runs by seeding with deterministic values derived from test node IDs.
Yes, if your test suite targets Python 3.5–3.7 and pytest versions from around 2019. The low install friction and permissive license make adoption straightforward. However, if you need modern Python versions or recent pytest support, verify compatibility first or seek an actively maintained alternative, since this package is abandoned.
Install
pytest-rng on PyPI
pip
pip install pytest-rnguv
uv add pytest-rngpoetry
poetry add pytest-rngInstalling pytest-rng
Before you install
Low install friction with a pure-Python wheel. However, the package is abandoned—last release was August 8, 2019. No recent maintenance or updates, so compatibility with modern pytest or Python versions is unverified.
License in practice
MIT license (permissive) places no restrictions on use, modification, or distribution in proprietary or open-source projects.
Quickstart
pip install pytest-rng
# In your test file:
import numpy as np
def test_example(rng, seed):
random_values = rng.uniform(-1, 1, size=3)
print(random_values) # Same output every run
Requires numpy and pytest as runtime dependencies; requires Python >=3.5.
Verify before relying
- Compatibility with pytest versions released after August 2019 and Python 3.8+
- Whether the numpy.random.mtrand.RandomState interface remains stable in current numpy versions
- Active maintenance or community forks addressing modern test framework changes
Package facts
| License | MIT license (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — numpy, pytest |
| Maintenance | abandoned — 2,563 days since the last release |
| First released | |
| Downloads | 156,336/month — #10,786 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_rng-1.0.0-py3-none-any.whl
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
pytorch-seedProvides reproducible random number generation…
permissive · top 15,000 on PyPI
random-addressGenerates random real US addresses with…
permissive · top 15,000 on PyPI
random2Provides Python 2.7's random module…
permissive · top 15,000 on PyPI
pyudorandomGenerates pseudorandom numbers using algebraic…
unclear · top 15,000 on PyPI
pytest-replayA pytest plugin that records test execution…
permissive · top 15,000 on PyPI
pytest-random-orderA pytest plugin that randomizes the order in…
permissive · top 5,000 on PyPI
pytest-postgresqlA pytest plugin that provides fixtures to…
copyleft · top 5,000 on PyPI
pytest-redisA pytest plugin that provides fixtures for…
copyleft · top 15,000 on PyPI
pytest-freezerpytest-freezer provides a pytest fixture that…
permissive · top 5,000 on PyPI