Avoid RuntimeError caused by iteration over sys.modules

As is described in the doc[1], we should not iterate over sys.modules
directly because sys.modules can be changed during iterations.

[1] https://docs.python.org/3/library/sys.html#sys.modules

Change-Id: Ib6ab36f93b408fdae59c1c08146f2ca069ed4f96
This commit is contained in:
Takashi Kajinami 2023-11-10 18:26:01 +09:00
parent ecdeadeb7a
commit 6410ca6518
1 changed files with 1 additions and 1 deletions

View File

@ -163,7 +163,7 @@ class YaqlEvaluatorTest(base.BaseTest):
def test_function_json_pp_deprecation(self):
with warnings.catch_warnings(record=True) as w:
# Ensure warnings aren't suppressed from other tests.
for name, mod in list(sys.modules.items()):
for name, mod in list(sys.modules.copy().items()):
getattr(mod, '__warningregistry__', dict()).clear()
warnings.simplefilter('always')