Skip to content

gh-103186: Suppress RuntimeWarning about unclosed async iterator in test_sys_settrace #109075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ async def asynciter(iterable):
for x in iterable:
yield x

def clean_asynciter(test):
@wraps(test)
async def wrapper(*args, **kwargs):
cleanups = []
def wrapped_asynciter(iterable):
it = asynciter(iterable)
cleanups.append(it.aclose)
return it
try:
return await test(*args, **kwargs, asynciter=wrapped_asynciter)
finally:
while cleanups:
await cleanups.pop()()
return wrapper

# A very basic example. If this fails, we're in deep trouble.
def basic():
Expand Down Expand Up @@ -1937,7 +1951,11 @@ def compare_jump_output(self, expected, received):

def run_test(self, func, jumpFrom, jumpTo, expected, error=None,
event='line', decorated=False, warning=None):
tracer = JumpTracer(func, jumpFrom, jumpTo, event, decorated)
wrapped = func
while hasattr(wrapped, '__wrapped__'):
wrapped = wrapped.__wrapped__

tracer = JumpTracer(wrapped, jumpFrom, jumpTo, event, decorated)
sys.settrace(tracer.trace)
output = []

Expand All @@ -1953,7 +1971,11 @@ def run_test(self, func, jumpFrom, jumpTo, expected, error=None,

def run_async_test(self, func, jumpFrom, jumpTo, expected, error=None,
event='line', decorated=False, warning=None):
tracer = JumpTracer(func, jumpFrom, jumpTo, event, decorated)
wrapped = func
while hasattr(wrapped, '__wrapped__'):
wrapped = wrapped.__wrapped__

tracer = JumpTracer(wrapped, jumpFrom, jumpTo, event, decorated)
sys.settrace(tracer.trace)
output = []

Expand Down Expand Up @@ -2024,15 +2046,17 @@ def test_jump_out_of_block_backwards(output):
output.append(7)

@async_jump_test(4, 5, [3, 5])
async def test_jump_out_of_async_for_block_forwards(output):
@clean_asynciter
async def test_jump_out_of_async_for_block_forwards(output, asynciter):
for i in [1]:
async for i in asynciter([1, 2]):
output.append(3)
output.append(4)
output.append(5)

@async_jump_test(5, 2, [2, 4, 2, 4, 5, 6])
async def test_jump_out_of_async_for_block_backwards(output):
@clean_asynciter
async def test_jump_out_of_async_for_block_backwards(output, asynciter):
for i in [1]:
output.append(2)
async for i in asynciter([1]):
Expand Down