[Zope3-checkins] SVN: zope.testing/trunk/src/zope/testing/testrunner.py Various code loves to reset the system trace function to None, even

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jun 13 17:36:05 EDT 2006


Log message for revision 68624:
  Various code loves to reset the system trace function to None, even 
  though they had not overridden it in the first place. I do not why, but 
  doctest does this too (unintentionally I think). Thus I provided a 
  simple wrapper around the sys.settrace function that ignores calls to 
  the funtion, if the argument is None while the coverage tracing is 
  activated.
  
  

Changed:
  U   zope.testing/trunk/src/zope/testing/testrunner.py

-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py	2006-06-13 21:31:43 UTC (rev 68623)
+++ zope.testing/trunk/src/zope/testing/testrunner.py	2006-06-13 21:36:04 UTC (rev 68624)
@@ -45,6 +45,15 @@
 
 real_pdb_set_trace = pdb.set_trace
 
+# For some reason, the doctest module resets the trace callable randomly, thus
+# disabling the coverage. Simply disallow the code from doing this. A real
+# trace can be set, so that debugging still works.
+osettrace = sys.settrace
+def settrace(trace):
+    if trace is None:
+        return
+    osettrace(trace)
+
 class TestIgnore:
 
     def __init__(self, options):
@@ -104,6 +113,7 @@
     def start(self):
         assert not self.started, "can't start if already started"
         if not self.donothing:
+            sys.settrace = settrace
             sys.settrace(self.globaltrace)
             threading.settrace(self.globaltrace)
         self.started = True
@@ -111,6 +121,7 @@
     def stop(self):
         assert self.started, "can't stop if not started"
         if not self.donothing:
+            sys.settrace = osettrace
             sys.settrace(None)
             threading.settrace(None)
         self.started = False



More information about the Zope3-Checkins mailing list