diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py index d78eaaca279..deeaa724e79 100644 --- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -1199,8 +1199,8 @@ class CoroutineTest(unittest.TestCase): def __aiter__(self): return self - anext_awaitable = anext(A(), "a").__await__() - self.assertRaises(TypeError, anext_awaitable.close, 1) + with contextlib.closing(anext(A(), "a").__await__()) as anext_awaitable: + self.assertRaises(TypeError, anext_awaitable.close, 1) def test_with_1(self): class Manager: