Skip to content

Commit

Permalink
rewrite sys modules mock
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Feb 16, 2024
1 parent a76e8b2 commit 2860dfc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/unitary/jupyter/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
def replace_modules():
mocked_modules = {}

anchor = sys.modules

def replace(modules: dict):
sys.modules = sys.modules.copy()
for module, mock in modules.items():
assert module not in sys.modules
sys.modules[module] = mock
mocked_modules[module] = mock

yield replace
for m in mocked_modules:
sys.modules.pop(m)

sys.modules = anchor


@pytest.fixture()
Expand Down

0 comments on commit 2860dfc

Please sign in to comment.