]> granicus.if.org Git - python/commitdiff
Fixes #10541: regrtest -T is broken
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Sun, 29 Jun 2014 21:44:05 +0000 (17:44 -0400)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Sun, 29 Jun 2014 21:44:05 +0000 (17:44 -0400)
 * makes test_trace tests restore the tracefunc after they run
 * write_results() in trace module will not terminate if lnotab
   cannot be found.

Lib/test/test_trace.py
Lib/trace.py

index 1cec710ee580faeaf5226ed2a8ae3a7c5093425c..05bf274ca8ac58fd2663fd0229518efaee6d33e2 100644 (file)
@@ -10,7 +10,6 @@ from trace import CoverageResults, Trace
 
 from test.tracedmodules import testmod
 
-
 #------------------------------- Utilities -----------------------------------#
 
 def fix_ext_py(filename):
@@ -224,6 +223,11 @@ class TestFuncs(unittest.TestCase):
         self.addCleanup(sys.settrace, sys.gettrace())
         self.tracer = Trace(count=0, trace=0, countfuncs=1)
         self.filemod = my_file_and_modname()
+        self._saved_tracefunc = sys.gettrace()
+
+    def tearDown(self):
+        if self._saved_tracefunc is not None:
+            sys.settrace(self._saved_tracefunc)
 
     def test_simple_caller(self):
         self.tracer.runfunc(traced_func_simple_caller, 1)
index 09fe9ee0e48f3fcf5182b2acf337fbff15e3499c..1c888acd99f3ccfc3c6f77915669f5ff13b8295b 100755 (executable)
@@ -326,16 +326,17 @@ class CoverageResults:
                 lnotab = _find_executable_linenos(filename)
             else:
                 lnotab = {}
+            if lnotab:
+                source = linecache.getlines(filename)
+                coverpath = os.path.join(dir, modulename + ".cover")
+                with open(filename, 'rb') as fp:
+                    encoding, _ = tokenize.detect_encoding(fp.readline)
+                n_hits, n_lines = self.write_results_file(coverpath, source,
+                                                          lnotab, count, encoding)
+                if summary and n_lines:
+                    percent = int(100 * n_hits / n_lines)
+                    sums[modulename] = n_lines, percent, modulename, filename
 
-            source = linecache.getlines(filename)
-            coverpath = os.path.join(dir, modulename + ".cover")
-            with open(filename, 'rb') as fp:
-                encoding, _ = tokenize.detect_encoding(fp.readline)
-            n_hits, n_lines = self.write_results_file(coverpath, source,
-                                                      lnotab, count, encoding)
-            if summary and n_lines:
-                percent = int(100 * n_hits / n_lines)
-                sums[modulename] = n_lines, percent, modulename, filename
 
         if summary and sums:
             print("lines   cov%   module   (path)")