Skip to content

Commit cb110b0

Browse files
authored
Merge pull request #983 from effigies/fix/optpkg_mock
TEST: Use more constrained mock when testing optpkg
2 parents a1a55ff + 84c7cf4 commit cb110b0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

nibabel/tests/test_optpkg.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def test_basic():
3939
# We never have package _not_a_package
4040
assert_bad('_not_a_package')
4141

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

0 commit comments

Comments
 (0)