From e8263ec9ec98081524a11542b324dc2caf2e7672 Mon Sep 17 00:00:00 2001 From: Mike Boyle Date: Tue, 20 Aug 2024 12:16:57 -0400 Subject: [PATCH] Avoid Windows failures due to missing SYSTEMROOT --- tests/test_utilities.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 72e6f89..2878c4b 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1,4 +1,6 @@ import subprocess +import platform +import os import sys import numpy as np import quaternionic @@ -123,13 +125,24 @@ def test_pyguvectorize(): @pytest.mark.skipif(sys.implementation.name.lower() == "pypy", reason="No numba on pypy") def test_cache_disable(tmp_path): + # Stolen from https://github.com/pypa/setuptools/blob/477f713450ff57de126153f3034d032542916d03/setuptools/tests/test_distutils_adoption.py#L13-L22 + def win_sr(env): + """ + On Windows, SYSTEMROOT must be present to avoid + + > Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python + """ + if platform.system() == "Windows": + env["SYSTEMROOT"] = os.environ["SYSTEMROOT"] + return env + # First check caching works by default. cache_dir = tmp_path / "enabled" subprocess.run( [sys.executable, "-c", "import quaternionic"], - env={ + env=win_sr({ "NUMBA_CACHE_DIR": str(cache_dir), - }, + }), ) # Numba uses a subdirectory named `quaternionic_`, with the hashstr computed @@ -147,9 +160,9 @@ def test_cache_disable(tmp_path): cache_dir = tmp_path / "disabled" subprocess.run( [sys.executable, "-c", "import quaternionic"], - env={ + env=win_sr({ "QUATERNIONIC_DISABLE_CACHE": "1", "NUMBA_CACHE_DIR": str(cache_dir), - }, + }), ) assert (not cache_dir.exists()) or len(list(cache_dir.iterdir())) == 0