mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-97837: Change deprecation warning message in unittest
(#97838)
This commit is contained in:
parent
4e731814d7
commit
c3648f4e4a
5 changed files with 37 additions and 8 deletions
|
@ -277,25 +277,36 @@ class TestAsyncCase(unittest.TestCase):
|
||||||
self.assertEqual(events, ['asyncSetUp', 'test', 'asyncTearDown', 'cleanup2', 'cleanup1'])
|
self.assertEqual(events, ['asyncSetUp', 'test', 'asyncTearDown', 'cleanup2', 'cleanup1'])
|
||||||
|
|
||||||
def test_deprecation_of_return_val_from_test(self):
|
def test_deprecation_of_return_val_from_test(self):
|
||||||
# Issue 41322 - deprecate return of value!=None from a test
|
# Issue 41322 - deprecate return of value that is not None from a test
|
||||||
|
class Nothing:
|
||||||
|
def __eq__(self, o):
|
||||||
|
return o is None
|
||||||
class Test(unittest.IsolatedAsyncioTestCase):
|
class Test(unittest.IsolatedAsyncioTestCase):
|
||||||
async def test1(self):
|
async def test1(self):
|
||||||
return 1
|
return 1
|
||||||
async def test2(self):
|
async def test2(self):
|
||||||
yield 1
|
yield 1
|
||||||
|
async def test3(self):
|
||||||
|
return Nothing()
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning) as w:
|
with self.assertWarns(DeprecationWarning) as w:
|
||||||
Test('test1').run()
|
Test('test1').run()
|
||||||
self.assertIn('It is deprecated to return a value!=None', str(w.warning))
|
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
|
||||||
self.assertIn('test1', str(w.warning))
|
self.assertIn('test1', str(w.warning))
|
||||||
self.assertEqual(w.filename, __file__)
|
self.assertEqual(w.filename, __file__)
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning) as w:
|
with self.assertWarns(DeprecationWarning) as w:
|
||||||
Test('test2').run()
|
Test('test2').run()
|
||||||
self.assertIn('It is deprecated to return a value!=None', str(w.warning))
|
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
|
||||||
self.assertIn('test2', str(w.warning))
|
self.assertIn('test2', str(w.warning))
|
||||||
self.assertEqual(w.filename, __file__)
|
self.assertEqual(w.filename, __file__)
|
||||||
|
|
||||||
|
with self.assertWarns(DeprecationWarning) as w:
|
||||||
|
Test('test3').run()
|
||||||
|
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
|
||||||
|
self.assertIn('test3', str(w.warning))
|
||||||
|
self.assertEqual(w.filename, __file__)
|
||||||
|
|
||||||
def test_cleanups_interleave_order(self):
|
def test_cleanups_interleave_order(self):
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
|
|
|
@ -307,25 +307,36 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
|
||||||
Foo('test').run()
|
Foo('test').run()
|
||||||
|
|
||||||
def test_deprecation_of_return_val_from_test(self):
|
def test_deprecation_of_return_val_from_test(self):
|
||||||
# Issue 41322 - deprecate return of value!=None from a test
|
# Issue 41322 - deprecate return of value that is not None from a test
|
||||||
|
class Nothing:
|
||||||
|
def __eq__(self, o):
|
||||||
|
return o is None
|
||||||
class Foo(unittest.TestCase):
|
class Foo(unittest.TestCase):
|
||||||
def test1(self):
|
def test1(self):
|
||||||
return 1
|
return 1
|
||||||
def test2(self):
|
def test2(self):
|
||||||
yield 1
|
yield 1
|
||||||
|
def test3(self):
|
||||||
|
return Nothing()
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning) as w:
|
with self.assertWarns(DeprecationWarning) as w:
|
||||||
Foo('test1').run()
|
Foo('test1').run()
|
||||||
self.assertIn('It is deprecated to return a value!=None', str(w.warning))
|
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
|
||||||
self.assertIn('test1', str(w.warning))
|
self.assertIn('test1', str(w.warning))
|
||||||
self.assertEqual(w.filename, __file__)
|
self.assertEqual(w.filename, __file__)
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning) as w:
|
with self.assertWarns(DeprecationWarning) as w:
|
||||||
Foo('test2').run()
|
Foo('test2').run()
|
||||||
self.assertIn('It is deprecated to return a value!=None', str(w.warning))
|
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
|
||||||
self.assertIn('test2', str(w.warning))
|
self.assertIn('test2', str(w.warning))
|
||||||
self.assertEqual(w.filename, __file__)
|
self.assertEqual(w.filename, __file__)
|
||||||
|
|
||||||
|
with self.assertWarns(DeprecationWarning) as w:
|
||||||
|
Foo('test3').run()
|
||||||
|
self.assertIn('It is deprecated to return a value that is not None', str(w.warning))
|
||||||
|
self.assertIn('test3', str(w.warning))
|
||||||
|
self.assertEqual(w.filename, __file__)
|
||||||
|
|
||||||
def _check_call_order__subtests(self, result, events, expected_events):
|
def _check_call_order__subtests(self, result, events, expected_events):
|
||||||
class Foo(Test.LoggingTestCase):
|
class Foo(Test.LoggingTestCase):
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
|
@ -88,7 +88,7 @@ class IsolatedAsyncioTestCase(TestCase):
|
||||||
|
|
||||||
def _callTestMethod(self, method):
|
def _callTestMethod(self, method):
|
||||||
if self._callMaybeAsync(method) is not None:
|
if self._callMaybeAsync(method) is not None:
|
||||||
warnings.warn(f'It is deprecated to return a value!=None from a '
|
warnings.warn(f'It is deprecated to return a value that is not None from a '
|
||||||
f'test case ({method})', DeprecationWarning, stacklevel=4)
|
f'test case ({method})', DeprecationWarning, stacklevel=4)
|
||||||
|
|
||||||
def _callTearDown(self):
|
def _callTearDown(self):
|
||||||
|
|
|
@ -577,7 +577,7 @@ class TestCase(object):
|
||||||
|
|
||||||
def _callTestMethod(self, method):
|
def _callTestMethod(self, method):
|
||||||
if method() is not None:
|
if method() is not None:
|
||||||
warnings.warn(f'It is deprecated to return a value!=None from a '
|
warnings.warn(f'It is deprecated to return a value that is not None from a '
|
||||||
f'test case ({method})', DeprecationWarning, stacklevel=3)
|
f'test case ({method})', DeprecationWarning, stacklevel=3)
|
||||||
|
|
||||||
def _callTearDown(self):
|
def _callTearDown(self):
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
Change deprecate warning message in :mod:`unittest` from
|
||||||
|
|
||||||
|
``It is deprecated to return a value!=None``
|
||||||
|
|
||||||
|
to
|
||||||
|
|
||||||
|
``It is deprecated to return a value that is not None from a test case``
|
Loading…
Add table
Add a link
Reference in a new issue