File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 22
33import importlib
44import pkgutil
5+ import subprocess
6+ import sys
57
68import pytest
79
@@ -21,3 +23,27 @@ def find_modules() -> list[str]:
2123def test_imports (module : str ):
2224 """All modules can be imported without throwing errors."""
2325 importlib .import_module (module )
26+
27+
28+ WHITELIST = [
29+ "baybe.acquisition.adapter" ,
30+ "baybe.acquisition.partial" ,
31+ "baybe.utils.botorch_wrapper" ,
32+ "baybe.utils.torch" ,
33+ ]
34+ """List of modules that are allowed to import torch."""
35+
36+
37+ def test_torch_lazy_loading ():
38+ """Torch does not appear in the module list after loading BayBE modules."""
39+ imps = "\n " .join ([f"import { i } " for i in find_modules () if i not in WHITELIST ])
40+ code = "\n " .join (
41+ [
42+ "import sys" ,
43+ f"{ imps } " ,
44+ "exit(int('torch' in sys.modules.keys()))" ,
45+ ]
46+ )
47+ python_interpreter = sys .executable
48+ result = subprocess .call ([python_interpreter , "-c" , code ])
49+ assert result == 0
You can’t perform that action at this time.
0 commit comments