From 4e6cb963bed3bbec6b4a332907c2b698c3f779ba Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 11 Jan 2025 13:26:13 +0200 Subject: [PATCH] gh-128729: Fix ResourceWarning in test_unittest --- Lib/test/test_unittest/test_case.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_unittest/test_case.py b/Lib/test/test_unittest/test_case.py index b4b2194a09cf9f..1e1599d1d0457e 100644 --- a/Lib/test/test_unittest/test_case.py +++ b/Lib/test/test_unittest/test_case.py @@ -346,8 +346,12 @@ class Foo(unittest.TestCase): async def test1(self): return 1 - with self.assertWarns(DeprecationWarning) as w: - Foo('test1').run() + with warnings.catch_warnings(): + # Ignore RuntimeWarning: coroutine '...' was never awaited + warnings.simplefilter("ignore", RuntimeWarning) + with self.assertWarns((DeprecationWarning, )) as w: + Foo('test1').run() + support.gc_collect() self.assertIn('It is deprecated to return a value that is not None', str(w.warning)) self.assertIn('test1', str(w.warning)) self.assertEqual(w.filename, __file__)