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:
Nikita Sobolev 2024-06-12 17:50:58 +03:00 committed by GitHub
parent 92c9c6ae14
commit fabcf6bc8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 6 deletions

View file

@ -90,9 +90,13 @@ def _callSetUp(self):
self._callAsync(self.asyncSetUp)
def _callTestMethod(self, method):
if self._callMaybeAsync(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=4)
result = self._callMaybeAsync(method)
if result is not None:
msg = (
f'It is deprecated to return a value that is not None '
f'from a test case ({method} returned {type(result).__name__!r})',
)
warnings.warn(msg, DeprecationWarning, stacklevel=4)
def _callTearDown(self):
self._callAsync(self.asyncTearDown)