skillfed

pytest-rng

Fixtures for seeding tests and making randomness reproducible

pytest-rng v1.0.0 156.3K downloads/30d#10,786 on PyPI
Permissive license MIT license Abandoned released

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

uv

uv add pytest-rng

poetry

poetry add pytest-rng

Installing 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

Development Status :: 5 - Production/StableFramework :: PytestLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7

Tags

pytest random seed fixturereproducible randomness testingdeterministic test rngnumpy random state pytestseeded random teststest randomness controlpytest fixture rng
reproducible-testingpytest-pluginrandom-seeding

More Testing packages