]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-97837: Change deprecation warning message in `unittest` (#97838)
authorNikita Sobolev <mail@sobolevn.me>
Wed, 5 Oct 2022 00:29:18 +0000 (03:29 +0300)
committerGitHub <noreply@github.com>
Wed, 5 Oct 2022 00:29:18 +0000 (17:29 -0700)
Lib/test/test_unittest/test_async_case.py
Lib/test/test_unittest/test_case.py
Lib/unittest/async_case.py
Lib/unittest/case.py
Misc/NEWS.d/next/Library/2022-10-04-21-21-41.gh-issue-97837.19q-eg.rst [new file with mode: 0644]

index d7d4dc91316c6c323daf0e63ba50ce1455a4b119..fab8270ea33abd600446e099b2b40819eecadac7 100644 (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 = []
 
index fae0d1076da948cc66de3ab60ee96af68d6123cd..05d60a8ad3cf948965306a7c8470a47a18052ab3 100644 (file)
@@ -307,25 +307,36 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
         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):
index 3457e92e5da298fa0995daee8ff9871aa968e13f..bd2a471156065bd0a1609ee6b9ed25baecb1bce5 100644 (file)
@@ -88,7 +88,7 @@ class IsolatedAsyncioTestCase(TestCase):
 
     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):
index af8303333d40876ee1d11ff5ffd837d46d8811dd..b01f6605e23e3915d5b029d6e7ae80e07883d48a 100644 (file)
@@ -577,7 +577,7 @@ class TestCase(object):
 
     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/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 (file)
index 0000000..b1350c9
--- /dev/null
@@ -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``