Skip to content

Commit f0490ab

Browse files
committed
check for multiple warnings in async def unittest
1 parent a3b61aa commit f0490ab

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Lib/test/test_unittest/test_case.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ResultWithNoStartTestRunStopTestRun
2121
)
2222
from test.support import captured_stderr, gc_collect
23+
from test.support.warnings_helper import check_warnings
2324

2425

2526
log_foo = logging.getLogger('foo')
@@ -346,15 +347,21 @@ class Foo(unittest.TestCase):
346347
async def test1(self):
347348
return 1
348349

349-
with self.assertWarns(DeprecationWarning) as w:
350+
with check_warnings(
351+
(r"coroutine .* was never awaited", RuntimeWarning),
352+
(r"It is deprecated to return a value that is not None", DeprecationWarning),
353+
) as recorder:
350354
Foo('test1').run()
351-
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
352-
self.assertIn('test1', str(w.warning))
353-
self.assertEqual(w.filename, __file__)
354-
self.assertIn("returned 'coroutine'", str(w.warning))
355+
w = recorder.warnings[0]
356+
warning = w.message
357+
filename = w.filename
358+
self.assertIn('It is deprecated to return a value that is not None', str(warning))
359+
self.assertIn('test1', str(warning))
360+
self.assertEqual(filename, __file__)
361+
self.assertIn("returned 'coroutine'", str(warning))
355362
self.assertIn(
356363
'Maybe you forgot to use IsolatedAsyncioTestCase as the base class?',
357-
str(w.warning),
364+
str(warning),
358365
)
359366

360367
def _check_call_order__subtests(self, result, events, expected_events):

0 commit comments

Comments
 (0)