From: andrei kulakov Date: Thu, 19 Aug 2021 09:41:04 +0000 (-0400) Subject: bpo-41322: added deprecation warning for tests returning value!=None (GH-27748) X-Git-Tag: v3.11.0a1~381 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3db42fc5aca320b0cac1895bc3cb731235ede794;p=thirdparty%2FPython%2Fcpython.git bpo-41322: added deprecation warning for tests returning value!=None (GH-27748) --- diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py index 86ed7046c499..cc404cc06f8b 100644 --- a/Lib/unittest/async_case.py +++ b/Lib/unittest/async_case.py @@ -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) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 872f12112755..3c771c0ca8e1 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -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 index 000000000000..e16efd2c7bd5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-08-12-16-22-16.bpo-41322.utscTd.rst @@ -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).