Skip to content

Commit 173b1bd

Browse files
committed
Use support.inject_memory_error_cm()
1 parent 4b5f32e commit 173b1bd

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

‎Lib/test/test_capi/test_bytes.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,8 @@ def test_format_s_memory_error(self):
567567
writer = self.create_writer()
568568
s = b'x' * 500
569569
with self.assertRaises(MemoryError):
570-
try:
571-
_testcapi.set_nomemory(0, 0)
570+
with support.inject_memory_error_cm():
572571
writer.format_s(b's=%s', s)
573-
finally:
574-
_testcapi.remove_mem_hooks()
575572
writer.write_bytes(b'after', -1)
576573

577574
@threading_helper.requires_working_threading()

‎Lib/test/test_dict.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,8 @@ def test_copy_empty_no_memory(self):
465465
d = {}
466466
d_copy = d.copy
467467
with self.assertRaises(MemoryError):
468-
try:
469-
_testcapi.set_nomemory(0)
468+
with support.inject_memory_error_cm():
470469
d_copy()
471-
finally:
472-
_testcapi.remove_mem_hooks()
473470

474471
def test_get(self):
475472
d = {}

0 commit comments

Comments
 (0)