[Checkins] SVN: Zope3/branches/jim-adapter/src/zope/deferredimport/tests.py We want the test to run the same way independent of warning settings,

Jim Fulton jim at zope.com
Thu Apr 6 06:20:27 EDT 2006


Log message for revision 66586:
  We want the test to run the same way independent of warning settings,
  so we temporarily replace warnings.warn with a version that has more
  deterministic behavior.
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/deferredimport/tests.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/deferredimport/tests.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/deferredimport/tests.py	2006-04-05 22:13:42 UTC (rev 66585)
+++ Zope3/branches/jim-adapter/src/zope/deferredimport/tests.py	2006-04-06 10:20:25 UTC (rev 66586)
@@ -11,7 +11,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-import os, re, shutil, sys, tempfile, unittest
+import os, re, shutil, sys, tempfile, unittest, warnings
 from zope.testing import doctest, renormalizing
 import zope.deferredimport
 
@@ -21,6 +21,22 @@
     def write(message):
         sys.stdout.write(message)
 
+def warn(message, type_, stacklevel):
+    frame = sys._getframe(stacklevel)
+    path = frame.f_globals['__file__']
+    file = open(path)
+    lineno = frame.f_lineno
+    for i in range(lineno):
+        line = file.readline()
+
+    print "%s:%s: %s: %s\n  %s" % (
+        path,
+        frame.f_lineno,
+        type_.__name__,
+        message,
+        line.strip(),
+        )
+
 def setUp(test):
     d = test.globs['tmp_d'] = tempfile.mkdtemp('deferredimport')
 
@@ -39,6 +55,9 @@
     test.globs['oldstderr'] = sys.stderr
     sys.stderr = OutErr
 
+    test.globs['saved_warn'] = warnings.warn
+    warnings.warn = warn
+
 def tearDown(test):
     sys.stderr = test.globs['oldstderr'] 
 
@@ -46,6 +65,7 @@
     shutil.rmtree(test.globs['tmp_d'])
     for name in test.globs['created_modules']:
         sys.modules.pop(name, None)
+    warnings.warn = test.globs['saved_warn']
 
 def test_suite():
     checker = renormalizing.RENormalizing((



More information about the Checkins mailing list