Skip to content

Commit a3d2714

Browse files
committed
rewrite test to @isolation.runInSubprocess()
1 parent 9d049e1 commit a3d2714

1 file changed

Lines changed: 22 additions & 26 deletions

File tree

Lib/test/test_class.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,34 +1113,30 @@ def test_prepare_preserves_order(self):
11131113

11141114

11151115
@support.nomemtest
1116+
@isolation.runInSubprocess()
11161117
def test_clear_managed_dict_no_memory_keeps_exception(self):
11171118
# gh-152083: an exception may already be set when the managed dict is
1118-
# cleared under low memory. PyErr_FormatUnraisable() must not clear it.
1119-
code = """if 1:
1120-
import _testcapi
1121-
1122-
class A:
1123-
def __init__(self):
1124-
self.a = 1
1125-
self.b = 2
1126-
1127-
def f():
1128-
a = A()
1129-
a.__dict__
1130-
return [None] * 1000
1131-
1132-
for start in range(120):
1133-
_testcapi.set_nomemory(start)
1134-
try:
1135-
f()
1136-
except BaseException:
1137-
pass
1138-
_testcapi.remove_mem_hooks()
1139-
"""
1140-
rc, out, err = script_helper.assert_python_ok("-c", code)
1141-
self.assertEqual(rc, 0)
1142-
self.assertFalse(out, msg=out.decode('utf-8'))
1143-
self.assertFalse(err, msg=err.decode('utf-8'))
1119+
# cleared under low memory. PyErr_FormatUnraisable() must not clear it.
1120+
import _testcapi
1121+
1122+
class A:
1123+
def __init__(self):
1124+
self.a = 1
1125+
self.b = 2
1126+
1127+
def f():
1128+
a = A()
1129+
a.__dict__
1130+
return [None] * 1000
1131+
1132+
for start in range(120):
1133+
_testcapi.set_nomemory(start)
1134+
try:
1135+
f()
1136+
except BaseException:
1137+
pass
1138+
_testcapi.remove_mem_hooks()
1139+
11441140

11451141
if __name__ == '__main__':
11461142
unittest.main()

0 commit comments

Comments
 (0)