Björn Tillenius has proposed merging ~bjornt/maas:pytest-seeds-cleanup into maas:master.
Commit message: Print out the seeds for pytest tests only if they fail. Requested reviews: MAAS Maintainers (maas-maintainers) For more details, see: https://code.launchpad.net/~bjornt/maas/+git/maas/+merge/433732 -- Your team MAAS Committers is subscribed to branch maas:master.
diff --git a/src/maastesting/pytest/seeds.py b/src/maastesting/pytest/seeds.py index 012744b..dee17cf 100644 --- a/src/maastesting/pytest/seeds.py +++ b/src/maastesting/pytest/seeds.py @@ -6,16 +6,35 @@ import time import pytest +maasseeds_stash = pytest.StashKey[str]() +pythonseeds_stash = pytest.StashKey[str]() + + [email protected] +def pytest_runtest_makereport(item, call): + if call.excinfo is None: + return + python_hash_seed = item.config.stash[pythonseeds_stash] + maas_rand_seed = item.config.stash[maasseeds_stash] + item.add_report_section( + "setup", + "seeds", + f"MAAS_RAND_SEED={maas_rand_seed} " + f"PYTHONHASHSEED={python_hash_seed}", + ) + @pytest.fixture(scope="session") -def configure_seeds(): +def configure_seeds(pytestconfig): maas_rand_seed = os.environ.get("MAAS_RAND_SEED") if maas_rand_seed is None: maas_rand_seed = time.time_ns() python_hash_seed = os.environ.get("PYTHONHASHSEED") if python_hash_seed is None: - python_hash_seed = random.randint(1, 4294967295) - os.environ["PYTHONHASHSEED"] = str(python_hash_seed) + python_hash_seed = str(random.randint(1, 4294967295)) + os.environ["PYTHONHASHSEED"] = python_hash_seed + pytestconfig.stash[maasseeds_stash] = str(maas_rand_seed) + pytestconfig.stash[pythonseeds_stash] = python_hash_seed return maas_rand_seed, python_hash_seed @@ -24,7 +43,3 @@ def random_seed(configure_seeds): maas_rand_seed, python_hash_seed = configure_seeds random.seed(maas_rand_seed) yield - print( - f"MAAS_RAND_SEED={maas_rand_seed} " - f"PYTHONHASHSEED={python_hash_seed}", - )
-- Mailing list: https://launchpad.net/~sts-sponsors Post to : [email protected] Unsubscribe : https://launchpad.net/~sts-sponsors More help : https://help.launchpad.net/ListHelp

