gh-97837: Change deprecation warning message in `unittest` (#97838) · python/cpython@c3648f4 · GitHub
Skip to content

Commit c3648f4

Browse files
authored
gh-97837: Change deprecation warning message in unittest (#97838)
1 parent 4e73181 commit c3648f4

5 files changed

Lines changed: 37 additions & 8 deletions

File tree

Lib/test/test_unittest/test_async_case.py

Lines changed: 14 additions & 3 deletions

Lib/test/test_unittest/test_case.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,36 @@ def test(self):
307307
Foo('test').run()
308308

309309
def test_deprecation_of_return_val_from_test(self):
310-
# Issue 41322 - deprecate return of value!=None from a test
310+
# Issue 41322 - deprecate return of value that is not None from a test
311+
class Nothing:
312+
def __eq__(self, o):
313+
return o is None
311314
class Foo(unittest.TestCase):
312315
def test1(self):
313316
return 1
314317
def test2(self):
315318
yield 1
319+
def test3(self):
320+
return Nothing()
316321

317322
with self.assertWarns(DeprecationWarning) as w:
318323
Foo('test1').run()
319-
self.assertIn('It is deprecated to return a value!=None', str(w.warning))
324+
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
320325
self.assertIn('test1', str(w.warning))
321326
self.assertEqual(w.filename, __file__)
322327

323328
with self.assertWarns(DeprecationWarning) as w:
324329
Foo('test2').run()
325-
self.assertIn('It is deprecated to return a value!=None', str(w.warning))
330+
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
326331
self.assertIn('test2', str(w.warning))
327332
self.assertEqual(w.filename, __file__)
328333

334+
with self.assertWarns(DeprecationWarning) as w:
335+
Foo('test3').run()
336+
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
337+
self.assertIn('test3', str(w.warning))
338+
self.assertEqual(w.filename, __file__)
339+
329340
def _check_call_order__subtests(self, result, events, expected_events):
330341
class Foo(Test.LoggingTestCase):
331342
def test(self):

Lib/unittest/async_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _callSetUp(self):
8888

8989
def _callTestMethod(self, method):
9090
if self._callMaybeAsync(method) is not None:
91-
warnings.warn(f'It is deprecated to return a value!=None from a '
91+
warnings.warn(f'It is deprecated to return a value that is not None from a '
9292
f'test case ({method})', DeprecationWarning, stacklevel=4)
9393

9494
def _callTearDown(self):

Lib/unittest/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def _callSetUp(self):
577577

578578
def _callTestMethod(self, method):
579579
if method() is not None:
580-
warnings.warn(f'It is deprecated to return a value!=None from a '
580+
warnings.warn(f'It is deprecated to return a value that is not None from a '
581581
f'test case ({method})', DeprecationWarning, stacklevel=3)
582582

583583
def _callTearDown(self):
Lines changed: 7 additions & 0 deletions

0 commit comments

Comments
 (0)