|
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): |
@@ -1104,6 +1104,23 @@ def test_unhandled(self): |
1104 | 1104 | self.assertIn("test message", report) |
1105 | 1105 | self.assertTrue(report.endswith("\n")) |
1106 | 1106 |
|
| 1107 | + @cpython_only |
| 1108 | + def test_memory_error_in_PyErr_PrintEx(self): |
| 1109 | + code = """if 1: |
| 1110 | + import _testcapi |
| 1111 | + class C(): pass |
| 1112 | + _testcapi.set_nomemory(0, %d) |
| 1113 | + C() |
| 1114 | + """ |
| 1115 | + |
| 1116 | + # Issue #30817: Abort in PyErr_PrintEx() when no memory. |
| 1117 | + # Span a large range of tests as the CPython code always evolves with |
| 1118 | + # changes that add or remove memory allocations. |
| 1119 | + for i in range(1, 20): |
| 1120 | + rc, out, err = script_helper.assert_python_failure("-c", code % i) |
| 1121 | + self.assertIn(rc, (1, 120)) |
| 1122 | + self.assertIn(b'MemoryError', err) |
| 1123 | + |
1107 | 1124 |
|
1108 | 1125 | class ImportErrorTests(unittest.TestCase): |
1109 | 1126 |
|
|
0 commit comments