diff --git a/tests/unit/test_block_step_sync.py b/tests/unit/test_block_step_sync.py index 51b76ca..3590fde 100644 --- a/tests/unit/test_block_step_sync.py +++ b/tests/unit/test_block_step_sync.py @@ -1,6 +1,7 @@ """Host contract of PeriodicBlockStepper.step(n): one stream wait per call (mocked driver).""" import ast from contextlib import nullcontext +import importlib.util from pathlib import Path import types from unittest.mock import Mock @@ -8,14 +9,15 @@ import unittest import numpy as np -import CelerisLab.lbm.block_stepper as b from CelerisLab.config import LBMConfig from CelerisLab.lbm.blocks import BlockLayout2D def host_module(): """block_stepper with pycuda/compiler replaced by mocks; no GPU context.""" - path = Path(b.__file__) + # Locate the source without importing it: importing block_stepper loads pycuda.driver, + # which CPU-only import-boundary tests (test_build_contracts) must never see. + path = Path(importlib.util.find_spec("CelerisLab.lbm.block_stepper").origin) tree = ast.parse(path.read_text()) tree.body = [node for node in tree.body if not ( isinstance(node, ast.Import) and any(a.name == "pycuda.driver" for a in node.names)