Skip to content

ERR: include original error message for missing required dependencies #26685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix for recursion in test
  • Loading branch information
DanielFEvans committed Jun 6, 2019
commit ab47d9904af44d1fe712042a1be0aff4fd0e9361
12 changes: 7 additions & 5 deletions pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,8 @@ def test_to_numpy_dtype(as_series):

@patch("builtins.__import__")
def test_missing_required_dependency(mock_import):
original_import = __import__

def mock_import_fail(name, *args, **kwargs):
if name == "numpy":
raise ImportError("cannot import name numpy")
Expand All @@ -1355,9 +1357,7 @@ def mock_import_fail(name, *args, **kwargs):
elif name == "dateutil":
raise ImportError("cannot import name some_other_dependency")
else:
return __import__(name, *args, **kwargs)

mock_import.side_effect = mock_import_fail
return original_import(name, *args, **kwargs)

expected_msg = (
"Unable to import required dependencies:"
Expand All @@ -1366,5 +1366,7 @@ def mock_import_fail(name, *args, **kwargs):
"\ndateutil: cannot import name some_other_dependency"
)

with pytest.raises(ImportError, match=expected_msg):
reload(pd)
with patch("builtins.__import__") as mock_import:
mock_import.side_effect = mock_import_fail
with pytest.raises(ImportError, match=expected_msg):
reload(pd)