From 3db42fc5aca320b0cac1895bc3cb731235ede794 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 19 Aug 2021 05:41:04 -0400 Subject: bpo-41322: added deprecation warning for tests returning value!=None (GH-27748) --- Lib/unittest/async_case.py | 5 ++++- Lib/unittest/case.py | 4 +++- Misc/NEWS.d/next/Library/2021-08-12-16-22-16.bpo-41322.utscTd.rst | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2021-08-12-16-22-16.bpo-41322.utscTd.rst diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py index 86ed704..cc404cc 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 872f121..3c771c0 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 0000000..e16efd2 --- /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). -- cgit v0.12