diff --git a/backend/tests/unit/test_delete_account_purge_storage.py b/backend/tests/unit/test_delete_account_purge_storage.py index 4cdefee2c1..e363325849 100644 --- a/backend/tests/unit/test_delete_account_purge_storage.py +++ b/backend/tests/unit/test_delete_account_purge_storage.py @@ -48,6 +48,7 @@ def __getattr__(self, name): 'pusher', 'modal', 'ulid', + 'pytz', 'twilio', ) @@ -58,6 +59,16 @@ def _should_stub(name: str) -> bool: return any(name == p or name.startswith(p + '.') for p in _STUB_PREFIXES) +def _remove_module_tree(prefix: str) -> None: + for name in list(sys.modules): + if name == prefix or name.startswith(prefix + '.'): + sys.modules.pop(name, None) + + +for _prefix in _STUB_PREFIXES: + _remove_module_tree(_prefix) + + class _StubFinder(importlib.abc.MetaPathFinder, importlib.abc.Loader): def __init__(self): self.created = set() diff --git a/backend/tests/unit/test_delete_account_stripe_cancel.py b/backend/tests/unit/test_delete_account_stripe_cancel.py index 4e648142b3..abbf96088d 100644 --- a/backend/tests/unit/test_delete_account_stripe_cancel.py +++ b/backend/tests/unit/test_delete_account_stripe_cancel.py @@ -47,6 +47,7 @@ def __getattr__(self, name): 'pusher', 'modal', 'ulid', + 'pytz', 'twilio', ) @@ -57,6 +58,16 @@ def _should_stub(name: str) -> bool: return any(name == p or name.startswith(p + '.') for p in _STUB_PREFIXES) +def _remove_module_tree(prefix: str) -> None: + for name in list(sys.modules): + if name == prefix or name.startswith(prefix + '.'): + sys.modules.pop(name, None) + + +for _prefix in _STUB_PREFIXES: + _remove_module_tree(_prefix) + + class _StubFinder(importlib.abc.MetaPathFinder, importlib.abc.Loader): def __init__(self): self.created = set()