summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_opcodes.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-07-21 04:44:04 (GMT)
committerGitHub <noreply@github.com>2018-07-21 04:44:04 (GMT)
commit06ca3f0c09d017b9d741553818459cca2d5da587 (patch)
tree7aeff5032be7b94064da2cedf68743d908d3ac6d /Lib/test/test_opcodes.py
parentf2626ce6d4136f13a506e34ca8631ff2eab85fd9 (diff)
downloadcpython-06ca3f0c09d017b9d741553818459cca2d5da587.zip
cpython-06ca3f0c09d017b9d741553818459cca2d5da587.tar.gz
cpython-06ca3f0c09d017b9d741553818459cca2d5da587.tar.bz2
bpo-34136: Make test_do_not_recreate_annotations more reliable. (GH-8364)
Diffstat (limited to 'Lib/test/test_opcodes.py')
-rw-r--r--Lib/test/test_opcodes.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py
index 6806c61..20de386 100644
--- a/Lib/test/test_opcodes.py
+++ b/Lib/test/test_opcodes.py
@@ -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):