[3.10] bpo-43988: Add test.support.check_disallow_instantiation() (GH-25757) (GH-26885)
(cherry picked from commit 4f725261c6cf23d259e8fdc205e12b76ef4d2d31, fbff5387c3e1f3904420fa5a27738c6c5881305b, and 8cec740820fc875117bfa7b6bdb10202ebeb8fd5)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Automerge-Triggered-By: GH:vstinner
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index e1b2c79..4231e96 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1,5 +1,6 @@
from test.support import (gc_collect, bigmemtest, _2G,
- cpython_only, captured_stdout)
+ cpython_only, captured_stdout,
+ check_disallow_instantiation)
import locale
import re
import sre_compile
@@ -2218,11 +2219,10 @@ def test_signedness(self):
@cpython_only
def test_disallow_instantiation(self):
# Ensure that the type disallows instantiation (bpo-43916)
- self.assertRaises(TypeError, re.Match)
- self.assertRaises(TypeError, re.Pattern)
+ check_disallow_instantiation(self, re.Match)
+ check_disallow_instantiation(self, re.Pattern)
pat = re.compile("")
- tp = type(pat.scanner(""))
- self.assertRaises(TypeError, tp)
+ check_disallow_instantiation(self, type(pat.scanner("")))
class ExternalTests(unittest.TestCase):