|
24 | 24 | import warnings as original_warnings |
25 | 25 | from warnings import deprecated |
26 | 26 |
|
27 | | - |
28 | 27 | py_warnings = import_helper.import_fresh_module('_py_warnings') |
29 | 28 | py_warnings._set_module(py_warnings) |
30 | 29 |
|
@@ -1237,6 +1236,25 @@ def test_issue31566(self): |
1237 | 1236 | support.swap_item(globals(), '__file__', None): |
1238 | 1237 | self.assertRaises(UserWarning, self.module.warn, 'bar') |
1239 | 1238 |
|
| 1239 | + @support.cpython_only |
| 1240 | + # Python built with Py_TRACE_REFS fail with a fatal error in |
| 1241 | + # _PyRefchain_Trace() on memory allocation error. |
| 1242 | + @unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build') |
| 1243 | + def test_issue151673(self): |
| 1244 | + # Skip this test if the _testcapi module isn't available. |
| 1245 | + _testcapi = import_helper.import_module('_testcapi') |
| 1246 | + # warn() shouldn't crash when the "<sys>" fallback filename |
| 1247 | + # can't be allocated under memory pressure. |
| 1248 | + code = """if 1: |
| 1249 | + import _testcapi, warnings |
| 1250 | + warnings.simplefilter("always") |
| 1251 | + _testcapi.set_nomemory(0) |
| 1252 | + warnings.warn("boom") |
| 1253 | + """ |
| 1254 | + rc, out, err = assert_python_failure("-c", code) |
| 1255 | + self.assertIn(rc, (1, 120)) |
| 1256 | + self.assertIn(b'MemoryError', err) |
| 1257 | + |
1240 | 1258 |
|
1241 | 1259 | class WarningsDisplayTests(BaseTest): |
1242 | 1260 |
|
|
0 commit comments