Skip to content

Commit 594de16

Browse files
gh-51524: Fix bug when calling trace.CoverageResults with valid infile (#99629)
Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent 276643e commit 594de16

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Lib/test/test_trace.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from pickle import dump
23
import sys
34
from test.support import captured_stdout
45
from test.support.os_helper import (TESTFN, rmtree, unlink)
@@ -412,6 +413,15 @@ def test_issue9936(self):
412413
self.assertIn(modname, coverage)
413414
self.assertEqual(coverage[modname], (5, 100))
414415

416+
def test_coverageresults_update(self):
417+
# Update empty CoverageResults with a non-empty infile.
418+
infile = TESTFN + '-infile'
419+
with open(infile, 'wb') as f:
420+
dump(({}, {}, {'caller': 1}), f, protocol=1)
421+
self.addCleanup(unlink, infile)
422+
results = trace.CoverageResults({}, {}, infile, {})
423+
self.assertEqual(results.callers, {'caller': 1})
424+
415425
### Tests that don't mess with sys.settrace and can be traced
416426
### themselves TODO: Skip tests that do mess with sys.settrace when
417427
### regrtest is invoked with -T option.

Lib/trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __init__(self, counts=None, calledfuncs=None, infile=None,
172172
try:
173173
with open(self.infile, 'rb') as f:
174174
counts, calledfuncs, callers = pickle.load(f)
175-
self.update(self.__class__(counts, calledfuncs, callers))
175+
self.update(self.__class__(counts, calledfuncs, callers=callers))
176176
except (OSError, EOFError, ValueError) as err:
177177
print(("Skipping counts file %r: %s"
178178
% (self.infile, err)), file=sys.stderr)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug when calling trace.CoverageResults with valid infile.

0 commit comments

Comments
 (0)