From 3d9f990c68b0b395240997e12da558b45ef82ff2 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Fri, 27 Sep 2024 16:04:37 +0200 Subject: [PATCH] Reset `random.seed()` before every test case --- noxfile.py | 5 +++++ poetry.lock | 17 ++++++++++++++++- pyproject.toml | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 45830ce..24be972 100644 --- a/noxfile.py +++ b/noxfile.py @@ -230,11 +230,14 @@ TEST_DEPENDENCIES = ( "packaging", "pytest", "pytest-cov", + "pytest-randomly", "semver", 'typing-extensions; python_version < "3.11"', # to support Python 3.9 & 3.10 "xdoctest", ) +TEST_RANDOM_SEED = "--randomly-seed=42" + @nox.session(python=SUPPORTED_PYTHONS) def test(session: nox.Session) -> None: @@ -250,6 +253,7 @@ def test(session: nox.Session) -> None: args = posargs or ( "--cov", "--no-cov-on-fail", + TEST_RANDOM_SEED, TESTS_LOCATION, ) @@ -294,6 +298,7 @@ def test_coverage_run(session: nox.Session) -> None: "run", "-m", "pytest", + TEST_RANDOM_SEED, TESTS_LOCATION, ) diff --git a/poetry.lock b/poetry.lock index f30fd5e..c402d6e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1219,6 +1219,21 @@ pytest = ">=4.6" [package.extras] testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] +[[package]] +name = "pytest-randomly" +version = "3.15.0" +description = "Pytest plugin to randomly order tests and control random.seed." +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest_randomly-3.15.0-py3-none-any.whl", hash = "sha256:0516f4344b29f4e9cdae8bce31c4aeebf59d0b9ef05927c33354ff3859eeeca6"}, + {file = "pytest_randomly-3.15.0.tar.gz", hash = "sha256:b908529648667ba5e54723088edd6f82252f540cc340d748d1fa985539687047"}, +] + +[package.dependencies] +importlib-metadata = {version = ">=3.6.0", markers = "python_version < \"3.10\""} +pytest = "*" + [[package]] name = "pyyaml" version = "6.0.2" @@ -1699,4 +1714,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "d5e420036c32cb6043efd303ae45663287a7bda00036c94fd9497f9346fde701" +content-hash = "31a7b1ad8dd8949814d1f397022e400cd37643c6f5e9e438054de472091bcd69" diff --git a/pyproject.toml b/pyproject.toml index 2e4f244..086646f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,6 +77,7 @@ coverage = "^7.6" packaging = "^24.1" # to test the version identifier pytest = "^8.3" pytest-cov = "^5.0" +pytest-randomly = "^3.15" semver = "^3.0" # to test the version identifier tomli = [ { python = "<3.11", version = "^2.0" } ] xdoctest = { extras = ["colors"], version = "^1.2" }