summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/case.py
diff options
context:
space:
mode:
authorkernc <kerncece@gmail.com>2020-06-11 18:03:29 (GMT)
committerGitHub <noreply@github.com>2020-06-11 18:03:29 (GMT)
commit46398fba4d66ad342cf2504ef947b5fb857423b2 (patch)
tree307f5e4c871dff3f0b83b8e930b61fddaf362993 /Lib/unittest/case.py
parent436b648910c27baf8164a6d46d746d36d8a93478 (diff)
downloadcpython-46398fba4d66ad342cf2504ef947b5fb857423b2.zip
cpython-46398fba4d66ad342cf2504ef947b5fb857423b2.tar.gz
cpython-46398fba4d66ad342cf2504ef947b5fb857423b2.tar.bz2
bpo-29620: iterate over a copy of sys.modules (GH-4800)
unittest.TestCase.assertWarns no longer raises a RuntimeException when accessing a module's ``__warningregistry__`` causes importation of a new module, or when a new module is imported in another thread. Patch by Kernc.
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r--Lib/unittest/case.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index f8bc865..52eb7d0 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -252,7 +252,7 @@ class _AssertWarnsContext(_AssertRaisesBaseContext):
def __enter__(self):
# The __warningregistry__'s need to be in a pristine state for tests
# to work properly.
- for v in sys.modules.values():
+ for v in list(sys.modules.values()):
if getattr(v, '__warningregistry__', None):
v.__warningregistry__ = {}
self.warnings_manager = warnings.catch_warnings(record=True)