Skip to content

Commit

Permalink
move mock definitions to inside the test
Browse files Browse the repository at this point in the history
  • Loading branch information
sroet committed Feb 27, 2024
1 parent 544f49e commit f4dd1fa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/test_broken_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ def cupy_import_error_mock(name, *args):
raise ImportError("Failed to import cupy")
return orig_import(name, *args)

matplotlib_not_found = module_not_found_mock('matplotlib.pyplot')
seaborn_not_found = module_not_found_mock('seaborn')

class TestMissingDependencies(unittest.TestCase):

Expand Down Expand Up @@ -47,6 +45,8 @@ def test_broken_cupy(self):
def test_missing_matplotlib(self):
# assert working import
import pytom_tm

matplotlib_not_found = module_not_found_mock('matplotlib.pyplot')
with unittest.mock.patch('builtins.__import__', side_effect=matplotlib_not_found):
with self.assertRaisesRegex(ModuleNotFoundError, 'matplotlib'):
# only pyplot is directly imported so this should be tested
Expand All @@ -66,6 +66,8 @@ def test_missing_matplotlib(self):
def test_missing_seaborn(self):
# assert working import
import pytom_tm

seaborn_not_found = module_not_found_mock('seaborn')
with unittest.mock.patch('builtins.__import__', side_effect=seaborn_not_found):
with self.assertRaisesRegex(ModuleNotFoundError, 'seaborn'):
import seaborn
Expand Down

0 comments on commit f4dd1fa

Please sign in to comment.