From fceb0ca2ac05268b1fee6099b2f5bc3f72d32cd1 Mon Sep 17 00:00:00 2001
From: Nikita Sobolev <mail@sobolevn.me>
Date: Wed, 5 Oct 2022 03:29:18 +0300
Subject: [PATCH] [3.11] gh-97837: Change deprecation warning message in
 `unittest` (GH-97838) (cherry picked from commit
 c3648f4e4a12ec6efe65684facfcd08996e550ca)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
---
 Lib/unittest/async_case.py                      |  2 +-
 Lib/unittest/case.py                            |  2 +-
 Lib/unittest/test/test_async_case.py            | 17 ++++++++++++++---
 Lib/unittest/test/test_case.py                  | 17 ++++++++++++++---
 ...022-10-04-21-21-41.gh-issue-97837.19q-eg.rst |  7 +++++++
 5 files changed, 37 insertions(+), 8 deletions(-)
 create mode 100644 Misc/NEWS.d/next/Library/2022-10-04-21-21-41.gh-issue-97837.19q-eg.rst

diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py
index 3457e92e5da..bd2a4711560 100644
--- a/Lib/unittest/async_case.py
+++ b/Lib/unittest/async_case.py
@@ -88,7 +88,7 @@ def _callSetUp(self):
 
     def _callTestMethod(self, method):
         if self._callMaybeAsync(method) is not None:
-            warnings.warn(f'It is deprecated to return a value!=None from a '
+            warnings.warn(f'It is deprecated to return a value that is not None from a '
                           f'test case ({method})', DeprecationWarning, stacklevel=4)
 
     def _callTearDown(self):
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index ffc8f19ddd3..8633f383760 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -577,7 +577,7 @@ def _callSetUp(self):
 
     def _callTestMethod(self, method):
         if method() is not None:
-            warnings.warn(f'It is deprecated to return a value!=None from a '
+            warnings.warn(f'It is deprecated to return a value that is not None from a '
                           f'test case ({method})', DeprecationWarning, stacklevel=3)
 
     def _callTearDown(self):
diff --git a/Lib/unittest/test/test_async_case.py b/Lib/unittest/test/test_async_case.py
index d7d4dc91316..fab8270ea33 100644
--- a/Lib/unittest/test/test_async_case.py
+++ b/Lib/unittest/test/test_async_case.py
@@ -277,25 +277,36 @@ async def on_cleanup2(self):
         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 = []
 
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 374a2552555..78303b359f5 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -307,25 +307,36 @@ def test(self):
         Foo('test').run()
 
     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 Foo(unittest.TestCase):
             def test1(self):
                 return 1
             def test2(self):
                 yield 1
+            def test3(self):
+                return Nothing()
 
         with self.assertWarns(DeprecationWarning) as w:
             Foo('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:
             Foo('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:
+            Foo('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 _check_call_order__subtests(self, result, events, expected_events):
         class Foo(Test.LoggingTestCase):
             def test(self):
diff --git a/Misc/NEWS.d/next/Library/2022-10-04-21-21-41.gh-issue-97837.19q-eg.rst b/Misc/NEWS.d/next/Library/2022-10-04-21-21-41.gh-issue-97837.19q-eg.rst
new file mode 100644
index 00000000000..b1350c959e2
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-10-04-21-21-41.gh-issue-97837.19q-eg.rst
@@ -0,0 +1,7 @@
+Change deprecate warning message in :mod:`unittest` from
+
+``It is deprecated to return a value!=None``
+
+to
+
+``It is deprecated to return a value that is not None from a test case``
-- 
GitLab