From e8e3a8f59514c1038b80a153742774b0e023d66a Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 15 Nov 2026 07:33:19 +0000 Subject: [PATCH] [mypyc] Close the runtime test driver's event loop Close the shared asyncio loop on exit so debug builds do not report an unclosed loop in the captured test output. --- mypyc/test-data/driver/driver.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mypyc/test-data/driver/driver.py b/mypyc/test-data/driver/driver.py index 55eba7d8b3dd7..399718b1a4a04 100644 --- a/mypyc/test-data/driver/driver.py +++ b/mypyc/test-data/driver/driver.py @@ -11,23 +11,23 @@ import native import asyncio import inspect - -evloop = asyncio.new_event_loop() +from contextlib import closing failures = [] tests_run = 0 -for name in dir(native): - if name.startswith('test_'): - test_func = getattr(native, name) - tests_run += 1 - try: - if inspect.iscoroutinefunction(test_func): - evloop.run_until_complete(test_func()) - else: - test_func() - except Exception as e: - failures.append((name, sys.exc_info())) +with closing(asyncio.new_event_loop()) as evloop: + for name in dir(native): + if name.startswith('test_'): + test_func = getattr(native, name) + tests_run += 1 + try: + if inspect.iscoroutinefunction(test_func): + evloop.run_until_complete(test_func()) + else: + test_func() + except Exception as e: + failures.append((name, sys.exc_info())) if failures: from traceback import print_exception, format_tb