]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41322: added deprecation warning for tests returning value!=None (GH-27748)
authorandrei kulakov <andrei.avk@gmail.com>
Thu, 19 Aug 2021 09:41:04 +0000 (05:41 -0400)
committerGitHub <noreply@github.com>
Thu, 19 Aug 2021 09:41:04 +0000 (11:41 +0200)
Lib/unittest/async_case.py
Lib/unittest/case.py
Misc/NEWS.d/next/Library/2021-08-12-16-22-16.bpo-41322.utscTd.rst [new file with mode: 0644]

index 86ed7046c499a374f953bf721f8c7eeeab2e4adc..cc404cc06f8b65a56fcce19681fe216260bd8caf 100644 (file)
@@ -1,5 +1,6 @@
 import asyncio
 import inspect
+import warnings
 
 from .case import TestCase
 
@@ -62,7 +63,9 @@ class IsolatedAsyncioTestCase(TestCase):
         self._callAsync(self.asyncSetUp)
 
     def _callTestMethod(self, method):
-        self._callMaybeAsync(method)
+        if self._callMaybeAsync(method) is not None:
+            warnings.warn(f'It is deprecated to return a value!=None from a '
+                          f'test case ({method})', DeprecationWarning)
 
     def _callTearDown(self):
         self._callAsync(self.asyncTearDown)
index 872f12112755e99dc53154bac166a93572dd95ae..3c771c0ca8e102db6633ad3a67f4df41752b2169 100644 (file)
@@ -546,7 +546,9 @@ class TestCase(object):
         self.setUp()
 
     def _callTestMethod(self, method):
-        method()
+        if method() is not None:
+            warnings.warn(f'It is deprecated to return a value!=None from a '
+                          f'test case ({method})', DeprecationWarning)
 
     def _callTearDown(self):
         self.tearDown()
diff --git a/Misc/NEWS.d/next/Library/2021-08-12-16-22-16.bpo-41322.utscTd.rst b/Misc/NEWS.d/next/Library/2021-08-12-16-22-16.bpo-41322.utscTd.rst
new file mode 100644 (file)
index 0000000..e16efd2
--- /dev/null
@@ -0,0 +1,3 @@
+Added ``DeprecationWarning`` for tests and async tests that return a
+value!=None (as this may indicate an improperly written test, for example a
+test written as a generator function).