diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py index 520213c3727555..0fc4f04ee5c214 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 @@ def _callSetUp(self): 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 872f12112755e9..3c771c0ca8e102 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -546,7 +546,9 @@ def _callSetUp(self): 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 00000000000000..e16efd2c7bd556 --- /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).