bpo-41322: Add unit tests for deprecation of test return values (GH-27846)

Also fix the traceback of warnings.
This commit is contained in:
andrei kulakov 2021-08-22 14:32:45 -04:00 committed by GitHub
parent 6dd1cdb0cf
commit b1db308c61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 2 deletions

View file

@ -167,6 +167,26 @@ class TestAsyncCase(unittest.TestCase):
test.run()
self.assertEqual(events, ['asyncSetUp', 'test', 'asyncTearDown', 'cleanup'])
def test_deprecation_of_return_val_from_test(self):
# Issue 41322 - deprecate return of value!=None from a test
class Test(unittest.IsolatedAsyncioTestCase):
async def test1(self):
return 1
async def test2(self):
yield 1
with self.assertWarns(DeprecationWarning) as w:
Test('test1').run()
self.assertIn('It is deprecated to return a value!=None', str(w.warnings[0].message))
self.assertIn('test1', str(w.warnings[0].message))
self.assertEqual(w.warnings[0].filename, __file__)
with self.assertWarns(DeprecationWarning) as w:
Test('test2').run()
self.assertIn('It is deprecated to return a value!=None', str(w.warnings[0].message))
self.assertIn('test2', str(w.warnings[0].message))
self.assertEqual(w.warnings[0].filename, __file__)
def test_cleanups_interleave_order(self):
events = []