Skip to content

Commit e99712c

Browse files
committed
fix tests for CI: import patching is finicky on different pythons
1 parent 0b3ca02 commit e99712c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ibllib/tests/extractors/test_extractors_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ def import_mock(self, name, *args):
3030
def test_get_task_extractor_map(self):
3131
"""Test ibllib.io.extractors.base._get_task_extractor_map function."""
3232
# Check the custom map is loaded
33-
with patch('builtins.__import__', side_effect=self.import_mock):
33+
with patch.dict('sys.modules', {'projects': self.projects}):
3434
extractors = base._get_task_extractor_map()
3535
self.assertTrue(self.custom_extractors.items() < extractors.items())
3636
# Test handles case where module not installed
37-
with patch('builtins.__import__', side_effect=ModuleNotFoundError):
37+
with patch.dict('sys.modules', {'projects': None}):
38+
# When trying to import a module that's None in sys.modules, it will raise ImportError
3839
extractors = base._get_task_extractor_map()
3940
self.assertFalse(set(self.custom_extractors.items()).issubset(set(extractors.items())))
4041
# Remove the file and check exception is caught

0 commit comments

Comments
 (0)