[Zope-Checkins] SVN: Zope/trunk/lib/python/
warnings.resetwarnings() should never be called by tests.
Tim Peters
tim.one at comcast.net
Mon Oct 31 18:43:55 EST 2005
Log message for revision 39802:
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.
Changed:
U Zope/trunk/lib/python/AccessControl/tests/testDeprecatedAPI.py
U Zope/trunk/lib/python/Zope2/Startup/tests/test_warnfilter.py
-=-
Modified: Zope/trunk/lib/python/AccessControl/tests/testDeprecatedAPI.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/tests/testDeprecatedAPI.py 2005-10-31 23:31:40 UTC (rev 39801)
+++ Zope/trunk/lib/python/AccessControl/tests/testDeprecatedAPI.py 2005-10-31 23:43:55 UTC (rev 39802)
@@ -25,10 +25,17 @@
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 @@
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', [], [])
Modified: Zope/trunk/lib/python/Zope2/Startup/tests/test_warnfilter.py
===================================================================
--- Zope/trunk/lib/python/Zope2/Startup/tests/test_warnfilter.py 2005-10-31 23:31:40 UTC (rev 39801)
+++ Zope/trunk/lib/python/Zope2/Startup/tests/test_warnfilter.py 2005-10-31 23:43:55 UTC (rev 39802)
@@ -46,11 +46,12 @@
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
More information about the Zope-Checkins
mailing list