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 ...@@ -25,10 +25,17 @@ import unittest, warnings
class DeprecatedAPI(unittest.TestCase): class DeprecatedAPI(unittest.TestCase):
def setUp(self): 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 # We test for warnings by turning them into exceptions
warnings.filterwarnings('error', category=DeprecationWarning, warnings.filterwarnings('error', category=DeprecationWarning,
module='AccessControl') module='AccessControl')
def tearDown(self):
warnings.filters[:] = self.original_warning_filters
def testDeprecatedHasRole(self): def testDeprecatedHasRole(self):
# hasRole has been deprecated, we expect a warning. # hasRole has been deprecated, we expect a warning.
try: try:
...@@ -48,11 +55,6 @@ class DeprecatedAPI(unittest.TestCase): ...@@ -48,11 +55,6 @@ class DeprecatedAPI(unittest.TestCase):
else: else:
pass pass
def tearDown(self):
warnings.resetwarnings()
warnings.simplefilter("ignore", category=PendingDeprecationWarning)
warnings.simplefilter("ignore", category=OverflowWarning)
class BasicUser(DeprecatedAPI): class BasicUser(DeprecatedAPI):
userObject = User.SimpleUser('JoeBloke', '123', [], []) userObject = User.SimpleUser('JoeBloke', '123', [], [])
......
...@@ -46,11 +46,12 @@ class TestWarnFilter(unittest.TestCase): ...@@ -46,11 +46,12 @@ class TestWarnFilter(unittest.TestCase):
def setUp(self): def setUp(self):
if self.schema is None: if self.schema is None:
TestWarnFilter.schema = getSchema() 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): def tearDown(self):
warnings.resetwarnings() warnings.filters[:] = self.original_warning_filters
warnings.simplefilter("ignore", category=PendingDeprecationWarning)
warnings.simplefilter("ignore", category=OverflowWarning)
def load_config_text(self, text): def load_config_text(self, text):
# We have to create a directory of our own since the existence # 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