|
10 | 10 |
|
11 | 11 | from test.support import (TESTFN, captured_stderr, check_impl_detail, |
12 | 12 | check_warnings, cpython_only, gc_collect, run_unittest, |
13 | | - no_tracing, unlink, import_module) |
| 13 | + no_tracing, unlink, import_module, script_helper) |
14 | 14 |
|
15 | 15 | class NaiveException(Exception): |
16 | 16 | def __init__(self, x): |
@@ -1097,6 +1097,23 @@ def test_unhandled(self): |
1097 | 1097 | self.assertIn("test message", report) |
1098 | 1098 | self.assertTrue(report.endswith("\n")) |
1099 | 1099 |
|
| 1100 | + @cpython_only |
| 1101 | + def test_memory_error_in_PyErr_PrintEx(self): |
| 1102 | + code = """if 1: |
| 1103 | + import _testcapi |
| 1104 | + class C(): pass |
| 1105 | + _testcapi.set_nomemory(0, %d) |
| 1106 | + C() |
| 1107 | + """ |
| 1108 | + |
| 1109 | + # Issue #30817: Abort in PyErr_PrintEx() when no memory. |
| 1110 | + # Span a large range of tests as the CPython code always evolves with |
| 1111 | + # changes that add or remove memory allocations. |
| 1112 | + for i in range(1, 20): |
| 1113 | + rc, out, err = script_helper.assert_python_failure("-c", code % i) |
| 1114 | + self.assertIn(rc, (1, 120)) |
| 1115 | + self.assertIn(b'MemoryError', err) |
| 1116 | + |
1100 | 1117 | def test_yield_in_nested_try_excepts(self): |
1101 | 1118 | #Issue #25612 |
1102 | 1119 | class MainError(Exception): |
|
0 commit comments