mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
warnings.catch_warnings() now returns a list or None instead of the custom
WarningsRecorder object. This makes the API simpler to use as no special object must be learned. Closes issue 3781. Review by Benjamin Peterson.
This commit is contained in:
parent
631be01252
commit
672237dc6c
24 changed files with 268 additions and 253 deletions
|
@ -5,7 +5,7 @@ import shutil
|
|||
import sys
|
||||
import py_compile
|
||||
import warnings
|
||||
from test.test_support import unlink, TESTFN, unload, run_unittest, catch_warning
|
||||
from test.test_support import unlink, TESTFN, unload, run_unittest
|
||||
|
||||
|
||||
def remove_files(name):
|
||||
|
@ -215,7 +215,7 @@ class ImportTest(unittest.TestCase):
|
|||
self.assert_(y is test.test_support, y.__name__)
|
||||
|
||||
def test_import_initless_directory_warning(self):
|
||||
with catch_warning():
|
||||
with warnings.catch_warnings():
|
||||
# Just a random non-package directory we always expect to be
|
||||
# somewhere in sys.path...
|
||||
warnings.simplefilter('error', ImportWarning)
|
||||
|
@ -279,17 +279,17 @@ class RelativeImport(unittest.TestCase):
|
|||
check_relative()
|
||||
# Check relative fails with only __package__ wrong
|
||||
ns = dict(__package__='foo', __name__='test.notarealmodule')
|
||||
with catch_warning() as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
check_absolute()
|
||||
self.assert_('foo' in str(w.message))
|
||||
self.assertEqual(w.category, RuntimeWarning)
|
||||
self.assert_('foo' in str(w[-1].message))
|
||||
self.assertEqual(w[-1].category, RuntimeWarning)
|
||||
self.assertRaises(SystemError, check_relative)
|
||||
# Check relative fails with __package__ and __name__ wrong
|
||||
ns = dict(__package__='foo', __name__='notarealpkg.notarealmodule')
|
||||
with catch_warning() as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
check_absolute()
|
||||
self.assert_('foo' in str(w.message))
|
||||
self.assertEqual(w.category, RuntimeWarning)
|
||||
self.assert_('foo' in str(w[-1].message))
|
||||
self.assertEqual(w[-1].category, RuntimeWarning)
|
||||
self.assertRaises(SystemError, check_relative)
|
||||
# Check both fail with package set to a non-string
|
||||
ns = dict(__package__=object())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue