Skip to content

Commit f3c1732

Browse files
committed
gh-144984: Address review: rename to cls.testcapi, add comment for assertRaises
1 parent be72e78 commit f3c1732

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Lib/test/test_pyexpat.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ class ExternalEntityParserCreateErrorTest(unittest.TestCase):
833833

834834
@classmethod
835835
def setUpClass(cls):
836-
cls._testcapi = import_helper.import_module('_testcapi')
836+
cls.testcapi = import_helper.import_module('_testcapi')
837837

838838
def test_error_path_no_crash(self):
839839
# When an allocation inside ExternalEntityParserCreate fails,
@@ -844,14 +844,17 @@ def test_error_path_no_crash(self):
844844
parser.buffer_text = True
845845
rc_before = sys.getrefcount(parser)
846846

847-
self._testcapi.set_nomemory(1, 10)
847+
# We avoid self.assertRaises(MemoryError) here because the
848+
# context manager itself needs memory allocations that fail
849+
# while the nomemory hook is active.
850+
self.testcapi.set_nomemory(1, 10)
848851
raised = False
849852
try:
850853
parser.ExternalEntityParserCreate(None)
851854
except MemoryError:
852855
raised = True
853856
finally:
854-
self._testcapi.remove_mem_hooks()
857+
self.testcapi.remove_mem_hooks()
855858
self.assertTrue(raised, "MemoryError not raised")
856859

857860
rc_after = sys.getrefcount(parser)

0 commit comments

Comments
 (0)