]> granicus.if.org Git - python/commitdiff
bpo-34136: Make test_do_not_recreate_annotations more reliable. (GH-8364)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 21 Jul 2018 04:44:04 +0000 (07:44 +0300)
committerGitHub <noreply@github.com>
Sat, 21 Jul 2018 04:44:04 +0000 (07:44 +0300)
Lib/test/test_opcodes.py

index 6806c616cbef3888a2b9ba2b54eef369fb166a81..20de3867bfae600ee477135d360a601d954e21a1 100644 (file)
@@ -1,7 +1,7 @@
 # Python test set -- part 2, opcodes
 
 import unittest
-from test import ann_module
+from test import ann_module, support
 
 class OpcodeTest(unittest.TestCase):
 
@@ -42,10 +42,14 @@ class OpcodeTest(unittest.TestCase):
         self.assertEqual(ns['__annotations__'], {'x': int, 1: 2})
 
     def test_do_not_recreate_annotations(self):
-        class C:
-            del __annotations__
-            with self.assertRaises(NameError):
-                x: int
+        annotations = {}
+        # Don't rely on the existence of the '__annotations__' global.
+        with support.swap_item(globals(), '__annotations__', annotations):
+            class C:
+                del __annotations__
+                x: int  # Updates the '__annotations__' global.
+        self.assertIn('x', annotations)
+        self.assertIs(annotations['x'], int)
 
     def test_raise_class_exceptions(self):