Skip to content

Commit 9b33ca0

Browse files
[3.6] bpo-34136: Make test_do_not_recreate_annotations more reliable. (GH-8364) (GH-8366)
(cherry picked from commit 06ca3f0) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent ec729d5 commit 9b33ca0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Lib/test/test_opcodes.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Python test set -- part 2, opcodes
22

33
import unittest
4-
from test import ann_module
4+
from test import ann_module, support
55

66
class OpcodeTest(unittest.TestCase):
77

@@ -42,10 +42,13 @@ def test_use_existing_annotations(self):
4242
self.assertEqual(ns['__annotations__'], {'x': int, 1: 2})
4343

4444
def test_do_not_recreate_annotations(self):
45-
class C:
46-
del __annotations__
47-
with self.assertRaises(NameError):
48-
x: int
45+
# Don't rely on the existence of the '__annotations__' global.
46+
with support.swap_item(globals(), '__annotations__', {}):
47+
del globals()['__annotations__']
48+
class C:
49+
del __annotations__
50+
with self.assertRaises(NameError):
51+
x: int
4952

5053
def test_raise_class_exceptions(self):
5154

0 commit comments

Comments
 (0)