mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Add test.test_support.guard_warnings_filter . This function returns a context
manager that protects warnings.filter from being modified once the context is exited.
This commit is contained in:
parent
c745df8519
commit
6d9520c4f0
6 changed files with 37 additions and 26 deletions
|
|
@ -1,10 +1,11 @@
|
|||
from test.test_support import TESTFN, run_unittest
|
||||
from test.test_support import TESTFN, run_unittest, guard_warnings_filter
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import py_compile
|
||||
import warnings
|
||||
|
||||
|
||||
def remove_files(name):
|
||||
|
|
@ -204,15 +205,11 @@ class ImportTest(unittest.TestCase):
|
|||
self.assert_(y is test.test_support, y.__name__)
|
||||
|
||||
def test_import_initless_directory_warning(self):
|
||||
import warnings
|
||||
oldfilters = warnings.filters[:]
|
||||
warnings.simplefilter('error', ImportWarning);
|
||||
try:
|
||||
with guard_warnings_filter():
|
||||
# Just a random non-package directory we always expect to be
|
||||
# somewhere in sys.path...
|
||||
warnings.simplefilter('error', ImportWarning)
|
||||
self.assertRaises(ImportWarning, __import__, "site-packages")
|
||||
finally:
|
||||
warnings.filters = oldfilters
|
||||
|
||||
def test_main(verbose=None):
|
||||
run_unittest(ImportTest)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue