|
20 | 20 | ResultWithNoStartTestRunStopTestRun |
21 | 21 | ) |
22 | 22 | from test.support import captured_stderr, gc_collect |
| 23 | +from test.support.warnings_helper import check_warnings |
23 | 24 |
|
24 | 25 |
|
25 | 26 | log_foo = logging.getLogger('foo') |
@@ -346,15 +347,21 @@ class Foo(unittest.TestCase): |
346 | 347 | async def test1(self): |
347 | 348 | return 1 |
348 | 349 |
|
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: |
350 | 354 | 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)) |
355 | 362 | self.assertIn( |
356 | 363 | 'Maybe you forgot to use IsolatedAsyncioTestCase as the base class?', |
357 | | - str(w.warning), |
| 364 | + str(warning), |
358 | 365 | ) |
359 | 366 |
|
360 | 367 | def _check_call_order__subtests(self, result, events, expected_events): |
|
0 commit comments