Skip to content

Commit f026dae

Browse files
committed
Fixes #10541: regrtest -T is broken
* makes test_trace tests restore the tracefunc after they run * write_results() in trace module will not terminate if lnotab cannot be found.
1 parent 15c6ed5 commit f026dae

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

‎Lib/test/test_trace.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from test.tracedmodules import testmod
1212

13-
1413
#------------------------------- Utilities -----------------------------------#
1514

1615
def fix_ext_py(filename):
@@ -224,6 +223,11 @@ def setUp(self):
224223
self.addCleanup(sys.settrace, sys.gettrace())
225224
self.tracer = Trace(count=0, trace=0, countfuncs=1)
226225
self.filemod = my_file_and_modname()
226+
self._saved_tracefunc = sys.gettrace()
227+
228+
def tearDown(self):
229+
if self._saved_tracefunc is not None:
230+
sys.settrace(self._saved_tracefunc)
227231

228232
def test_simple_caller(self):
229233
self.tracer.runfunc(traced_func_simple_caller, 1)

‎Lib/trace.py‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,17 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
326326
lnotab = _find_executable_linenos(filename)
327327
else:
328328
lnotab = {}
329+
if lnotab:
330+
source = linecache.getlines(filename)
331+
coverpath = os.path.join(dir, modulename + ".cover")
332+
with open(filename, 'rb') as fp:
333+
encoding, _ = tokenize.detect_encoding(fp.readline)
334+
n_hits, n_lines = self.write_results_file(coverpath, source,
335+
lnotab, count, encoding)
336+
if summary and n_lines:
337+
percent = int(100 * n_hits / n_lines)
338+
sums[modulename] = n_lines, percent, modulename, filename
329339

330-
source = linecache.getlines(filename)
331-
coverpath = os.path.join(dir, modulename + ".cover")
332-
with open(filename, 'rb') as fp:
333-
encoding, _ = tokenize.detect_encoding(fp.readline)
334-
n_hits, n_lines = self.write_results_file(coverpath, source,
335-
lnotab, count, encoding)
336-
if summary and n_lines:
337-
percent = int(100 * n_hits / n_lines)
338-
sums[modulename] = n_lines, percent, modulename, filename
339340

340341
if summary and sums:
341342
print("lines cov% module (path)")

0 commit comments

Comments
 (0)