From c873d5673b467e265aad3c26fc20239da5b9a7b9 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Thu, 11 Jan 2024 21:21:55 +0100 Subject: [PATCH] Add exception handler --- pyfakefs/fake_filesystem_unittest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyfakefs/fake_filesystem_unittest.py b/pyfakefs/fake_filesystem_unittest.py index fb766aae..f877777c 100644 --- a/pyfakefs/fake_filesystem_unittest.py +++ b/pyfakefs/fake_filesystem_unittest.py @@ -1096,7 +1096,11 @@ def cleanup(self) -> None: for name in self._loaded_module_names: if name in sys.modules and name not in reloaded_module_names: print(f"Reload {name} patched: {name in Patcher.PATCHED_MODULE_NAMES}") - reload(sys.modules[name]) + try: + reload(sys.modules[name]) + except Exception: + print(f"Failed to reload - delete {name}") + del sys.modules[name] def needs_patch(self, name: str) -> bool: """Check if the module with the given name shall be replaced."""