Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Unreleased

* Drop Python 3.10 support.

* Initialize the configured seed when the report header is disabled, including quiet output and runs without the terminal plugin.

5.0.0 (2026-09-01)
------------------

Expand Down
7 changes: 5 additions & 2 deletions src/pytest_randomly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from _pytest.config.argparsing import Parser
from _pytest.fixtures import SubRequest
from _pytest.nodes import Item
from pytest import Collector, fixture, hookimpl
from pytest import Collector, Session, fixture, hookimpl

# factory-boy
try:
Expand Down Expand Up @@ -184,9 +184,12 @@ def _reseed(config: Config, offset: int = 0) -> int:
return seed


def pytest_sessionstart(session: Session) -> None:
_reseed(session.config)


def pytest_report_header(config: Config) -> str:
seed = config.getoption("randomly_seed")
_reseed(config)
return f"Using --randomly-seed={seed}"


Expand Down
26 changes: 26 additions & 0 deletions tests/test_pytest_randomly.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ def test_it_reports_a_header_when_set(simpletester):
assert lines == ["Using --randomly-seed=10"]


@pytest.mark.parametrize(
"output_args", [(), ("-q",), ("-qq",), ("--no-header",), ("-p", "no:terminal")]
)
def test_initial_seed_does_not_require_a_report_header(ourtester, output_args):
ourtester.makepyfile(
test_one="""
import random

expected = random.Random(123)

def test_a():
assert random.random() == expected.random()

def test_b():
assert random.random() == expected.random()
"""
)
out = ourtester.runpytest_subprocess(
"--randomly-seed=123",
"--randomly-dont-reorganize",
"--randomly-dont-reset-seed",
*output_args,
)
assert out.ret == 0


def test_it_uses_different_random_seeds_per_test(ourtester):
"""
Run a pair of tests that generate the a number and then assert they got
Expand Down