Reset random.seed() before every test case

This commit is contained in:
Alexander Hess 2024-09-27 16:04:37 +02:00
parent 4c0c7887e5
commit 3d9f990c68
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
3 changed files with 22 additions and 1 deletions

View file

@ -230,11 +230,14 @@ TEST_DEPENDENCIES = (
"packaging", "packaging",
"pytest", "pytest",
"pytest-cov", "pytest-cov",
"pytest-randomly",
"semver", "semver",
'typing-extensions; python_version < "3.11"', # to support Python 3.9 & 3.10 'typing-extensions; python_version < "3.11"', # to support Python 3.9 & 3.10
"xdoctest", "xdoctest",
) )
TEST_RANDOM_SEED = "--randomly-seed=42"
@nox.session(python=SUPPORTED_PYTHONS) @nox.session(python=SUPPORTED_PYTHONS)
def test(session: nox.Session) -> None: def test(session: nox.Session) -> None:
@ -250,6 +253,7 @@ def test(session: nox.Session) -> None:
args = posargs or ( args = posargs or (
"--cov", "--cov",
"--no-cov-on-fail", "--no-cov-on-fail",
TEST_RANDOM_SEED,
TESTS_LOCATION, TESTS_LOCATION,
) )
@ -294,6 +298,7 @@ def test_coverage_run(session: nox.Session) -> None:
"run", "run",
"-m", "-m",
"pytest", "pytest",
TEST_RANDOM_SEED,
TESTS_LOCATION, TESTS_LOCATION,
) )

17
poetry.lock generated
View file

@ -1219,6 +1219,21 @@ pytest = ">=4.6"
[package.extras] [package.extras]
testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] 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]] [[package]]
name = "pyyaml" name = "pyyaml"
version = "6.0.2" version = "6.0.2"
@ -1699,4 +1714,4 @@ type = ["pytest-mypy"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.9" python-versions = "^3.9"
content-hash = "d5e420036c32cb6043efd303ae45663287a7bda00036c94fd9497f9346fde701" content-hash = "31a7b1ad8dd8949814d1f397022e400cd37643c6f5e9e438054de472091bcd69"

View file

@ -77,6 +77,7 @@ coverage = "^7.6"
packaging = "^24.1" # to test the version identifier packaging = "^24.1" # to test the version identifier
pytest = "^8.3" pytest = "^8.3"
pytest-cov = "^5.0" pytest-cov = "^5.0"
pytest-randomly = "^3.15"
semver = "^3.0" # to test the version identifier semver = "^3.0" # to test the version identifier
tomli = [ { python = "<3.11", version = "^2.0" } ] tomli = [ { python = "<3.11", version = "^2.0" } ]
xdoctest = { extras = ["colors"], version = "^1.2" } xdoctest = { extras = ["colors"], version = "^1.2" }