mirror of
https://github.com/python/cpython.git
synced 2026-06-27 19:36:07 +00:00
[3.15] gh-152236: Fix skips on _testcapi.set_nomemory tests (GH-152253) (#152281)
gh-152236: Fix skips on `_testcapi.set_nomemory` tests (GH-152253)
(cherry picked from commit 1cbe460eb6)
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
parent
7ed673718b
commit
a89de4b230
9 changed files with 32 additions and 42 deletions
|
|
@ -35,7 +35,7 @@
|
|||
"requires_gil_enabled", "requires_linux_version", "requires_mac_ver",
|
||||
"check_syntax_error",
|
||||
"requires_gzip", "requires_bz2", "requires_lzma", "requires_zstd",
|
||||
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
|
||||
"bigmemtest", "nomemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
|
||||
"requires_IEEE_754", "requires_zlib",
|
||||
"has_fork_support", "requires_fork",
|
||||
"has_subprocess_support", "requires_subprocess",
|
||||
|
|
@ -1314,6 +1314,22 @@ def wrapper(self):
|
|||
return wrapper
|
||||
return decorator
|
||||
|
||||
def nomemtest(f):
|
||||
"""Check that we can use this test with `_testcapi.set_nomemory`."""
|
||||
from .import_helper import import_module
|
||||
|
||||
@functools.wraps(f)
|
||||
def internal(*args, **kwargs):
|
||||
import_module('_testcapi')
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return unittest.skipIf(
|
||||
# Python built with Py_TRACE_REFS fail with a fatal error in
|
||||
# _PyRefchain_Trace() on memory allocation error.
|
||||
Py_TRACE_REFS,
|
||||
'cannot test Py_TRACE_REFS build',
|
||||
)(cpython_only(internal))
|
||||
|
||||
def bigaddrspacetest(f):
|
||||
"""Decorator for tests that fill the address space."""
|
||||
def wrapper(self):
|
||||
|
|
|
|||
|
|
@ -191,9 +191,7 @@ def callback():
|
|||
self.assertEqual(os.read(r, len(expected)), expected)
|
||||
os.close(r)
|
||||
|
||||
# Python built with Py_TRACE_REFS fail with a fatal error in
|
||||
# _PyRefchain_Trace() on memory allocation error.
|
||||
@unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
|
||||
@support.nomemtest
|
||||
def test_atexit_with_low_memory(self):
|
||||
# gh-140080: Test that setting low memory after registering an atexit
|
||||
# callback doesn't cause an infinite loop during finalization.
|
||||
|
|
|
|||
|
|
@ -117,9 +117,7 @@ def test_pyobject_forbidden_bytes_is_freed(self):
|
|||
def test_pyobject_freed_is_freed(self):
|
||||
self.check_pyobject_is_freed('check_pyobject_freed_is_freed')
|
||||
|
||||
# Python built with Py_TRACE_REFS fail with a fatal error in
|
||||
# _PyRefchain_Trace() on memory allocation error.
|
||||
@unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
|
||||
@support.nomemtest
|
||||
def test_set_nomemory(self):
|
||||
code = """if 1:
|
||||
import _testcapi
|
||||
|
|
|
|||
|
|
@ -449,7 +449,6 @@ def __delattr__(self, *args):
|
|||
|
||||
def testHasAttrString(self):
|
||||
import sys
|
||||
from test.support import import_helper
|
||||
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
|
||||
|
||||
class A:
|
||||
|
|
@ -1013,11 +1012,8 @@ class C:
|
|||
C.a = X()
|
||||
C.a = X()
|
||||
|
||||
@cpython_only
|
||||
@support.nomemtest
|
||||
def test_detach_materialized_dict_no_memory(self):
|
||||
# Skip test if _testcapi is not available:
|
||||
import_helper.import_module('_testcapi')
|
||||
|
||||
code = """if 1:
|
||||
import test.support
|
||||
import _testcapi
|
||||
|
|
|
|||
|
|
@ -1583,11 +1583,7 @@ def recurse_in_body_and_except():
|
|||
sys.setrecursionlimit(recursionlimit)
|
||||
|
||||
|
||||
@cpython_only
|
||||
# Python built with Py_TRACE_REFS fail with a fatal error in
|
||||
# _PyRefchain_Trace() on memory allocation error.
|
||||
@unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
|
||||
@unittest.skipIf(_testcapi is None, "requires _testcapi")
|
||||
@support.nomemtest
|
||||
def test_recursion_normalizing_with_no_memory(self):
|
||||
# Issue #30697. Test that in the abort that occurs when there is no
|
||||
# memory left and the size of the Python frames stack is greater than
|
||||
|
|
@ -1774,11 +1770,7 @@ def test_unhandled(self):
|
|||
self.assertIn("test message", report)
|
||||
self.assertEndsWith(report, "\n")
|
||||
|
||||
@cpython_only
|
||||
# Python built with Py_TRACE_REFS fail with a fatal error in
|
||||
# _PyRefchain_Trace() on memory allocation error.
|
||||
@unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
|
||||
@unittest.skipIf(_testcapi is None, "requires _testcapi")
|
||||
@support.nomemtest
|
||||
def test_memory_error_in_PyErr_PrintEx(self):
|
||||
code = """if 1:
|
||||
import _testcapi
|
||||
|
|
@ -1936,12 +1928,8 @@ def test_keyerror_context(self):
|
|||
exc2 = None
|
||||
|
||||
|
||||
@cpython_only
|
||||
# Python built with Py_TRACE_REFS fail with a fatal error in
|
||||
# _PyRefchain_Trace() on memory allocation error.
|
||||
@unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
|
||||
@support.nomemtest
|
||||
def test_exec_set_nomemory_hang(self):
|
||||
import_module("_testcapi")
|
||||
# gh-134163: A MemoryError inside code that was wrapped by a try/except
|
||||
# block would lead to an infinite loop.
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
from test.support import import_helper
|
||||
from test.support import threading_helper
|
||||
# Raise SkipTest if subinterpreters not supported.
|
||||
import_helper.import_module('_interpreters')
|
||||
_interpreters = import_helper.import_module('_interpreters')
|
||||
from concurrent import interpreters
|
||||
from concurrent.interpreters import InterpreterError
|
||||
from .utils import TestBase
|
||||
|
|
@ -75,12 +75,13 @@ def run():
|
|||
start.set()
|
||||
support.gc_collect()
|
||||
|
||||
@support.nomemtest
|
||||
def test_create_interpreter_no_memory(self):
|
||||
import _interpreters
|
||||
_testcapi = import_helper.import_module("_testcapi")
|
||||
import _testcapi
|
||||
|
||||
with self.assertRaises(InterpreterError):
|
||||
_testcapi.set_nomemory(0, 1)
|
||||
assertion = self.assertRaises(InterpreterError)
|
||||
_testcapi.set_nomemory(0, 1)
|
||||
with assertion:
|
||||
_interpreters.create()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
import textwrap
|
||||
from test import list_tests, support
|
||||
from test.support import cpython_only
|
||||
from test.support.import_helper import import_module
|
||||
from test.support.script_helper import assert_python_failure, assert_python_ok
|
||||
import pickle
|
||||
import unittest
|
||||
|
|
@ -326,10 +325,9 @@ def test_tier2_invalidates_iterator(self):
|
|||
a.append(4)
|
||||
self.assertEqual(list(it), [])
|
||||
|
||||
@support.cpython_only
|
||||
@support.nomemtest
|
||||
def test_no_memory(self):
|
||||
# gh-118331: Make sure we don't crash if list allocation fails
|
||||
import_module("_testcapi")
|
||||
code = textwrap.dedent("""
|
||||
import _testcapi, sys
|
||||
# Prime the freelist
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
SHORT_TIMEOUT,
|
||||
)
|
||||
from test.support.script_helper import kill_python
|
||||
from test.support.import_helper import import_module
|
||||
|
||||
try:
|
||||
import pty
|
||||
|
|
@ -99,12 +98,8 @@ def run_on_interactive_mode(source):
|
|||
@support.force_not_colorized_test_class
|
||||
class TestInteractiveInterpreter(unittest.TestCase):
|
||||
|
||||
@cpython_only
|
||||
# Python built with Py_TRACE_REFS fail with a fatal error in
|
||||
# _PyRefchain_Trace() on memory allocation error.
|
||||
@unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
|
||||
@support.nomemtest
|
||||
def test_no_memory(self):
|
||||
import_module("_testcapi")
|
||||
# Issue #30696: Fix the interactive interpreter looping endlessly when
|
||||
# no memory. Check also that the fix does not break the interactive
|
||||
# loop when an exception is raised.
|
||||
|
|
|
|||
|
|
@ -1019,7 +1019,7 @@ def __del__(self): pass
|
|||
del x
|
||||
support.gc_collect()
|
||||
|
||||
@support.cpython_only
|
||||
@support.nomemtest
|
||||
def test_no_memory_when_clearing(self):
|
||||
# gh-118331: Make sure we do not raise an exception from the destructor
|
||||
# when clearing weakrefs if allocating the intermediate tuple fails.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue