summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-05-26 14:15:27 (GMT)
committerGitHub <noreply@github.com>2021-05-26 14:15:27 (GMT)
commit4f725261c6cf23d259e8fdc205e12b76ef4d2d31 (patch)
tree4e8e33e74cce4a7b6ef57d5e97fde49af6a4fbb4 /Lib/test/support
parent46db39d7bd67fb9fea133cd4f18cdf7eacb0f6d9 (diff)
downloadcpython-4f725261c6cf23d259e8fdc205e12b76ef4d2d31.zip
cpython-4f725261c6cf23d259e8fdc205e12b76ef4d2d31.tar.gz
cpython-4f725261c6cf23d259e8fdc205e12b76ef4d2d31.tar.bz2
bpo-43988: Add test.support.check_disallow_instantiation() (GH-25757)
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/__init__.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 80f3a04..8c6e554 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -40,6 +40,7 @@ __all__ = [
"requires_IEEE_754", "requires_zlib",
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__", "skip_if_buggy_ucrt_strfptime",
+ "check_disallow_instantiation",
# sys
"is_jython", "is_android", "check_impl_detail", "unix_shell",
"setswitchinterval",
@@ -1982,3 +1983,13 @@ def skip_if_broken_multiprocessing_synchronize():
synchronize.Lock(ctx=None)
except OSError as exc:
raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")
+
+
+def check_disallow_instantiation(testcase, tp, *args, **kwds):
+ """
+ Helper for testing types with the Py_TPFLAGS_DISALLOW_INSTANTIATION flag.
+
+ See bpo-43916.
+ """
+ msg = f"cannot create '{tp.__module__}\.{tp.__name__}' instances"
+ testcase.assertRaisesRegex(TypeError, msg, tp, *args, **kwds)