From 6a3a552449294477f5a1de5c82adf0e3f7c429a6 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Thu, 11 Jan 2024 21:04:51 +0100 Subject: [PATCH] Delete and reload --- pyfakefs/fake_filesystem_unittest.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyfakefs/fake_filesystem_unittest.py b/pyfakefs/fake_filesystem_unittest.py index ece2dd8c..e08ffb4c 100644 --- a/pyfakefs/fake_filesystem_unittest.py +++ b/pyfakefs/fake_filesystem_unittest.py @@ -1091,15 +1091,15 @@ def cleanup(self) -> None: reloaded_module_names = [ module.__name__ for module in self._patcher.modules_to_reload ] - # Reload all modules loaded and patched during the test, ensuring that + # Reload all modules loaded during the test, ensuring that # no faked modules are referenced after the test. + modules_to_reload = [] for name in self._loaded_module_names: if name in sys.modules and name not in reloaded_module_names: - # in the unlikely case that the cache is turned off, - # we have to reload all modules - # if not self._patcher.use_cache or name in Patcher.CACHED_MODULES: - reload(sys.modules[name]) - # del sys.modules[name] + modules_to_reload.append(sys.modules[name]) + del sys.modules[name] + for module in modules_to_reload: + reload(module) def needs_patch(self, name: str) -> bool: """Check if the module with the given name shall be replaced."""