Skip to content

Commit 3db42fc

Browse files
authored
bpo-41322: added deprecation warning for tests returning value!=None (GH-27748)
1 parent 0fd66e4 commit 3db42fc

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Lib/unittest/async_case.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import inspect
3+
import warnings
34

45
from .case import TestCase
56

@@ -62,7 +63,9 @@ def _callSetUp(self):
6263
self._callAsync(self.asyncSetUp)
6364

6465
def _callTestMethod(self, method):
65-
self._callMaybeAsync(method)
66+
if self._callMaybeAsync(method) is not None:
67+
warnings.warn(f'It is deprecated to return a value!=None from a '
68+
f'test case ({method})', DeprecationWarning)
6669

6770
def _callTearDown(self):
6871
self._callAsync(self.asyncTearDown)

Lib/unittest/case.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,9 @@ def _callSetUp(self):
546546
self.setUp()
547547

548548
def _callTestMethod(self, method):
549-
method()
549+
if method() is not None:
550+
warnings.warn(f'It is deprecated to return a value!=None from a '
551+
f'test case ({method})', DeprecationWarning)
550552

551553
def _callTearDown(self):
552554
self.tearDown()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Added ``DeprecationWarning`` for tests and async tests that return a
2+
value!=None (as this may indicate an improperly written test, for example a
3+
test written as a generator function).

0 commit comments

Comments
 (0)