diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-04-24 07:23:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-24 07:23:59 (GMT) |
commit | 090721721b373c50544d297b56c217cf15992cbe (patch) | |
tree | eac831fb9a94fa4fec902c6dda217c60abfcc38d /Lib/unittest | |
parent | b4e048411f4c62ad7343bca32c307f0bf5ef74b4 (diff) | |
download | cpython-090721721b373c50544d297b56c217cf15992cbe.zip cpython-090721721b373c50544d297b56c217cf15992cbe.tar.gz cpython-090721721b373c50544d297b56c217cf15992cbe.tar.bz2 |
Simplify testing the warning filename (GH-91868)
The context manager result has the "filename" attribute.
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/test/test_async_case.py | 12 | ||||
-rw-r--r-- | Lib/unittest/test/test_case.py | 12 | ||||
-rw-r--r-- | Lib/unittest/test/test_loader.py | 6 |
3 files changed, 15 insertions, 15 deletions
diff --git a/Lib/unittest/test/test_async_case.py b/Lib/unittest/test/test_async_case.py index a481408..1b910a4 100644 --- a/Lib/unittest/test/test_async_case.py +++ b/Lib/unittest/test/test_async_case.py @@ -259,15 +259,15 @@ class TestAsyncCase(unittest.TestCase): with self.assertWarns(DeprecationWarning) as w: Test('test1').run() - self.assertIn('It is deprecated to return a value!=None', str(w.warnings[0].message)) - self.assertIn('test1', str(w.warnings[0].message)) - self.assertEqual(w.warnings[0].filename, __file__) + self.assertIn('It is deprecated to return a value!=None', str(w.warning)) + self.assertIn('test1', str(w.warning)) + self.assertEqual(w.filename, __file__) with self.assertWarns(DeprecationWarning) as w: Test('test2').run() - self.assertIn('It is deprecated to return a value!=None', str(w.warnings[0].message)) - self.assertIn('test2', str(w.warnings[0].message)) - self.assertEqual(w.warnings[0].filename, __file__) + self.assertIn('It is deprecated to return a value!=None', str(w.warning)) + self.assertIn('test2', str(w.warning)) + self.assertEqual(w.filename, __file__) def test_cleanups_interleave_order(self): events = [] diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index f6cb997..374a255 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -316,15 +316,15 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): with self.assertWarns(DeprecationWarning) as w: Foo('test1').run() - self.assertIn('It is deprecated to return a value!=None', str(w.warnings[0].message)) - self.assertIn('test1', str(w.warnings[0].message)) - self.assertEqual(w.warnings[0].filename, __file__) + self.assertIn('It is deprecated to return a value!=None', str(w.warning)) + self.assertIn('test1', str(w.warning)) + self.assertEqual(w.filename, __file__) with self.assertWarns(DeprecationWarning) as w: Foo('test2').run() - self.assertIn('It is deprecated to return a value!=None', str(w.warnings[0].message)) - self.assertIn('test2', str(w.warnings[0].message)) - self.assertEqual(w.warnings[0].filename, __file__) + self.assertIn('It is deprecated to return a value!=None', str(w.warning)) + self.assertIn('test2', str(w.warning)) + self.assertEqual(w.filename, __file__) def _check_call_order__subtests(self, result, events, expected_events): class Foo(Test.LoggingTestCase): diff --git a/Lib/unittest/test/test_loader.py b/Lib/unittest/test/test_loader.py index 90e2081..de2268c 100644 --- a/Lib/unittest/test/test_loader.py +++ b/Lib/unittest/test/test_loader.py @@ -1609,7 +1609,7 @@ class TestObsoleteFunctions(unittest.TestCase): tests = unittest.getTestCaseNames(self.MyTestCase, prefix='check', sortUsing=self.reverse_three_way_cmp, testNamePatterns=None) - self.assertEqual(w.warnings[0].filename, __file__) + self.assertEqual(w.filename, __file__) self.assertEqual(tests, ['check_2', 'check_1']) def test_makeSuite(self): @@ -1617,7 +1617,7 @@ class TestObsoleteFunctions(unittest.TestCase): suite = unittest.makeSuite(self.MyTestCase, prefix='check', sortUsing=self.reverse_three_way_cmp, suiteClass=self.MyTestSuite) - self.assertEqual(w.warnings[0].filename, __file__) + self.assertEqual(w.filename, __file__) self.assertIsInstance(suite, self.MyTestSuite) expected = self.MyTestSuite([self.MyTestCase('check_2'), self.MyTestCase('check_1')]) @@ -1631,7 +1631,7 @@ class TestObsoleteFunctions(unittest.TestCase): suite = unittest.findTestCases(m, prefix='check', sortUsing=self.reverse_three_way_cmp, suiteClass=self.MyTestSuite) - self.assertEqual(w.warnings[0].filename, __file__) + self.assertEqual(w.filename, __file__) self.assertIsInstance(suite, self.MyTestSuite) expected = [self.MyTestSuite([self.MyTestCase('check_2'), self.MyTestCase('check_1')])] |