Skip to content

Commit 4e6cb96

Browse files
gh-128729: Fix ResourceWarning in test_unittest
1 parent 3a570c6 commit 4e6cb96

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Lib/test/test_unittest/test_case.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,12 @@ class Foo(unittest.TestCase):
346346
async def test1(self):
347347
return 1
348348

349-
with self.assertWarns(DeprecationWarning) as w:
350-
Foo('test1').run()
349+
with warnings.catch_warnings():
350+
# Ignore RuntimeWarning: coroutine '...' was never awaited
351+
warnings.simplefilter("ignore", RuntimeWarning)
352+
with self.assertWarns((DeprecationWarning, )) as w:
353+
Foo('test1').run()
354+
support.gc_collect()
351355
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
352356
self.assertIn('test1', str(w.warning))
353357
self.assertEqual(w.filename, __file__)

0 commit comments

Comments
 (0)