[3.11] gh-97837: Change deprecation warning message in unittest (GH-97838) (GH-97887)

(cherry picked from commit c3648f4e4a)


Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

Automerge-Triggered-By: GH:orsenthil
This commit is contained in:
Miss Islington (bot) 2022-10-04 20:55:06 -07:00 committed by GitHub
parent 9133aabc70
commit 8c517d88fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 8 deletions

View file

@ -277,25 +277,36 @@ class TestAsyncCase(unittest.TestCase):
self.assertEqual(events, ['asyncSetUp', 'test', 'asyncTearDown', 'cleanup2', 'cleanup1'])
def test_deprecation_of_return_val_from_test(self):
# Issue 41322 - deprecate return of value!=None from a test
# Issue 41322 - deprecate return of value that is not None from a test
class Nothing:
def __eq__(self, o):
return o is None
class Test(unittest.IsolatedAsyncioTestCase):
async def test1(self):
return 1
async def test2(self):
yield 1
async def test3(self):
return Nothing()
with self.assertWarns(DeprecationWarning) as w:
Test('test1').run()
self.assertIn('It is deprecated to return a value!=None', str(w.warning))
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__)
with self.assertWarns(DeprecationWarning) as w:
Test('test2').run()
self.assertIn('It is deprecated to return a value!=None', str(w.warning))
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
self.assertIn('test2', str(w.warning))
self.assertEqual(w.filename, __file__)
with self.assertWarns(DeprecationWarning) as w:
Test('test3').run()
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
self.assertIn('test3', str(w.warning))
self.assertEqual(w.filename, __file__)
def test_cleanups_interleave_order(self):
events = []