Skip to content

Commit b61a06f

Browse files
committed
Add @nomemtest decorator to the test, move the _testcapi call into the test method to avoid import issues, improve the syntax for handling the expected MemoryError
1 parent c25ac11 commit b61a06f

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Lib/test/test_interpreters/test_channels.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
# Raise SkipTest if subinterpreters not supported.
1010
_channels = import_helper.import_module('_interpchannels')
1111
from concurrent import interpreters
12-
from test.support import channels
12+
from test.support import channels, nomemtest
1313
from .utils import _run_output, TestBase
14-
import _testcapi
1514

1615

1716
class LowLevelTests(TestBase):
@@ -31,16 +30,18 @@ def test_highlevel_reloaded(self):
3130
# See gh-115490 (https://github.com/python/cpython/issues/115490).
3231
importlib.reload(channels)
3332

33+
@nomemtest
3434
def test_lock_allocation_failure(self):
3535
# see gh-152635 (https://github.com/python/cpython/issues/152635)
3636
# The first allocation to happen is the lock, which
3737
# historically triggered an assert if alloc failed.
38+
import _testcapi
39+
3840
cid = None
3941
_testcapi.set_nomemory(0, 1)
4042
try:
41-
cid = _channels.create()
42-
except MemoryError:
43-
pass # MemoryError is expected behavior
43+
with self.assertRaises(MemoryError):
44+
cid = _channels.create()
4445
finally:
4546
_testcapi.remove_mem_hooks()
4647
if cid is not None:

0 commit comments

Comments
 (0)