Commit 06ca3f0c authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-34136: Make test_do_not_recreate_annotations more reliable. (GH-8364)

parent f2626ce6
# Python test set -- part 2, opcodes # Python test set -- part 2, opcodes
import unittest import unittest
from test import ann_module from test import ann_module, support
class OpcodeTest(unittest.TestCase): class OpcodeTest(unittest.TestCase):
...@@ -42,10 +42,14 @@ class OpcodeTest(unittest.TestCase): ...@@ -42,10 +42,14 @@ class OpcodeTest(unittest.TestCase):
self.assertEqual(ns['__annotations__'], {'x': int, 1: 2}) self.assertEqual(ns['__annotations__'], {'x': int, 1: 2})
def test_do_not_recreate_annotations(self): def test_do_not_recreate_annotations(self):
annotations = {}
# Don't rely on the existence of the '__annotations__' global.
with support.swap_item(globals(), '__annotations__', annotations):
class C: class C:
del __annotations__ del __annotations__
with self.assertRaises(NameError): x: int # Updates the '__annotations__' global.
x: int self.assertIn('x', annotations)
self.assertIs(annotations['x'], int)
def test_raise_class_exceptions(self): def test_raise_class_exceptions(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment