|
1 | 1 | """
|
2 | 2 | Testing that we work in the downstream packages
|
3 | 3 | """
|
4 |
| -import builtins |
5 | 4 | import importlib
|
6 | 5 | import subprocess
|
7 | 6 | import sys
|
@@ -134,30 +133,13 @@ def test_pyarrow(df):
|
134 | 133 | tm.assert_frame_equal(result, df)
|
135 | 134 |
|
136 | 135 |
|
137 |
| -def test_missing_required_dependency(monkeypatch): |
| 136 | +def test_missing_required_dependency(): |
138 | 137 | # GH 23868
|
139 |
| - original_import = __import__ |
140 |
| - |
141 |
| - def mock_import_fail(name, *args, **kwargs): |
142 |
| - if name == "numpy": |
143 |
| - raise ImportError("cannot import name numpy") |
144 |
| - elif name == "pytz": |
145 |
| - raise ImportError("cannot import name some_dependency") |
146 |
| - elif name == "dateutil": |
147 |
| - raise ImportError("cannot import name some_other_dependency") |
148 |
| - else: |
149 |
| - return original_import(name, *args, **kwargs) |
150 |
| - |
151 |
| - expected_msg = ( |
152 |
| - "Unable to import required dependencies:" |
153 |
| - "\nnumpy: cannot import name numpy" |
154 |
| - "\npytz: cannot import name some_dependency" |
155 |
| - "\ndateutil: cannot import name some_other_dependency" |
156 |
| - ) |
157 |
| - |
158 |
| - import pandas as pd |
159 |
| - |
160 |
| - with monkeypatch.context() as m: |
161 |
| - m.setattr(builtins, "__import__", mock_import_fail) |
162 |
| - with pytest.raises(ImportError, match=expected_msg): |
163 |
| - importlib.reload(pd) |
| 138 | + # use the -S flag to disable site-packages |
| 139 | + call = ['python', '-S', '-c', 'import pandas'] |
| 140 | + |
| 141 | + with pytest.raises(subprocess.CalledProcessError) as exc: |
| 142 | + subprocess.check_output(call, stderr=subprocess.STDOUT) |
| 143 | + |
| 144 | + output = exc.value.stdout.decode() |
| 145 | + assert all(x in output for x in ['numpy', 'pytz', 'dateutil']) |
0 commit comments