mirror of
https://github.com/python/cpython.git
synced 2025-12-09 10:37:17 +00:00
gh-120388: Improve deprecation warning message, when test returns non-None (#120401)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
92c9c6ae14
commit
fabcf6bc8f
5 changed files with 44 additions and 6 deletions
|
|
@ -603,9 +603,18 @@ class TestCase(object):
|
|||
self.setUp()
|
||||
|
||||
def _callTestMethod(self, method):
|
||||
if method() is not None:
|
||||
warnings.warn(f'It is deprecated to return a value that is not None from a '
|
||||
f'test case ({method})', DeprecationWarning, stacklevel=3)
|
||||
result = method()
|
||||
if result is not None:
|
||||
import inspect
|
||||
msg = (
|
||||
f'It is deprecated to return a value that is not None '
|
||||
f'from a test case ({method} returned {type(result).__name__!r})'
|
||||
)
|
||||
if inspect.iscoroutine(result):
|
||||
msg += (
|
||||
'. Maybe you forgot to use IsolatedAsyncioTestCase as the base class?'
|
||||
)
|
||||
warnings.warn(msg, DeprecationWarning, stacklevel=3)
|
||||
|
||||
def _callTearDown(self):
|
||||
self.tearDown()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue