Commit 5b356795 authored by Tim Peters's avatar Tim Peters

warnings.resetwarnings() should never be called by tests.

Doing so wipes out all the warning filters other tests may set
up to suppress warnings those tests need to provoke but want to
hide from the entity running the tests.

This stops all the DeprecationWarnings that were displayed from
the ZODB and ZEO tests when running Zope trunk's test suite.
parent 24865e72
......@@ -25,10 +25,17 @@ import unittest, warnings
class DeprecatedAPI(unittest.TestCase):
def setUp(self):
# There is no official API to restore warning filters to a previous
# state. Here we cheat.
self.original_warning_filters = warnings.filters[:]
# We test for warnings by turning them into exceptions
warnings.filterwarnings('error', category=DeprecationWarning,
module='AccessControl')
def tearDown(self):
warnings.filters[:] = self.original_warning_filters
def testDeprecatedHasRole(self):
# hasRole has been deprecated, we expect a warning.
try:
......@@ -48,11 +55,6 @@ class DeprecatedAPI(unittest.TestCase):
else:
pass
def tearDown(self):
warnings.resetwarnings()
warnings.simplefilter("ignore", category=PendingDeprecationWarning)
warnings.simplefilter("ignore", category=OverflowWarning)
class BasicUser(DeprecatedAPI):
userObject = User.SimpleUser('JoeBloke', '123', [], [])
......
......@@ -46,11 +46,12 @@ class TestWarnFilter(unittest.TestCase):
def setUp(self):
if self.schema is None:
TestWarnFilter.schema = getSchema()
# There is no official API to restore warning filters to a previous
# state. Here we cheat.
self.original_warning_filters = warnings.filters[:]
def tearDown(self):
warnings.resetwarnings()
warnings.simplefilter("ignore", category=PendingDeprecationWarning)
warnings.simplefilter("ignore", category=OverflowWarning)
warnings.filters[:] = self.original_warning_filters
def load_config_text(self, text):
# We have to create a directory of our own since the existence
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment