Skip to content

TEST: Use more constrained mock when testing optpkg #983

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 1 commit into from
Dec 21, 2020
Merged
Changes from all commits
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
12 changes: 6 additions & 6 deletions nibabel/tests/test_optpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def test_basic():
# We never have package _not_a_package
assert_bad('_not_a_package')

# setup_module imports unittest, so make sure we don't disrupt that
# Only disrupt imports for "nottriedbefore" package
orig_import = builtins.__import__
def raise_Exception(*args, **kwargs):
if args[0] == 'unittest':
return orig_import(*args, **kwargs)
raise Exception(
"non ImportError could be thrown by some malfunctioning module "
"upon import, and optional_package should catch it too")
if args[0] == 'nottriedbefore':
raise Exception(
"non ImportError could be thrown by some malfunctioning module "
"upon import, and optional_package should catch it too")
return orig_import(*args, **kwargs)
with mock.patch.object(builtins, '__import__', side_effect=raise_Exception):
assert_bad('nottriedbefore')

Expand Down