Skip to content

Commit 463af75

Browse files
committed
fixup! feat(core.utils): run subprocess from neutral cwd to avoid source-tree shadow
1 parent b27ed2c commit 463af75

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

cuda_core/tests/test_program_cache.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ def close(self):
112112
assert closed == [True]
113113

114114

115-
def test_cuda_core_utils_memoryview_import_is_lightweight():
115+
def test_cuda_core_utils_memoryview_import_is_lightweight(tmp_path):
116116
"""``from cuda.core.utils import StridedMemoryView`` must NOT transitively
117117
import the program-cache backends; the cache modules pull in extra
118118
driver/NVRTC machinery that memoryview-only consumers have no reason
119119
to load."""
120-
import os
121120
import subprocess
122121
import sys
123122
import textwrap
@@ -135,12 +134,11 @@ def test_cuda_core_utils_memoryview_import_is_lightweight():
135134
_ = u.make_program_cache_key
136135
assert "cuda.core.utils._program_cache" in sys.modules
137136
""")
138-
# Forward pytest's sys.path to the subprocess via PYTHONPATH so it can
139-
# find the same cuda.core install the parent process is using (CI runs
140-
# may rely on pytest-added rootdirs that env-only inheritance misses).
141-
env = os.environ.copy()
142-
env["PYTHONPATH"] = os.pathsep.join(filter(None, sys.path))
143-
subprocess.run([sys.executable, "-c", prog], check=True, env=env) # noqa: S603
137+
# Run from a neutral cwd so Python's implicit ``sys.path[0]=''`` does not
138+
# resolve to the unbuilt cuda_core source tree (which lacks the
139+
# setuptools-scm-generated ``_version.py``). The subprocess must import
140+
# the installed cuda.core from site-packages.
141+
subprocess.run([sys.executable, "-c", prog], check=True, cwd=str(tmp_path)) # noqa: S603
144142

145143

146144
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)