Skip to content

Commit 1272d80

Browse files
authored
Merge pull request #76 from honno/nonp
Introduce `--nonp` to error when NumPy is accessed
2 parents 960894c + fc43e1c commit 1272d80

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

torch_np/tests/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24

35

@@ -7,6 +9,17 @@ def pytest_configure(config):
79

810
def pytest_addoption(parser):
911
parser.addoption("--runslow", action="store_true", help="run slow tests")
12+
parser.addoption("--nonp", action="store_true", help="error when NumPy is accessed")
13+
14+
15+
def pytest_sessionstart(session):
16+
if session.config.getoption("--nonp"):
17+
18+
class Inaccessible:
19+
def __getattribute__(self, attr):
20+
raise RuntimeError(f"Using --nonp but accessed np.{attr}")
21+
22+
sys.modules["numpy"] = Inaccessible()
1023

1124

1225
def pytest_collection_modifyitems(config, items):

0 commit comments

Comments
 (0)