Skip to content

Commit 345aaa4

Browse files
miss-islingtonfurkanonderterryjreedy
authored
gh-51524: Fix bug when calling trace.CoverageResults with valid infile (GH-99629)
(cherry picked from commit 594de16) Co-authored-by: Furkan Onder <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent ab87bcd commit 345aaa4

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)
@@ -407,6 +408,15 @@ def test_issue9936(self):
407408
self.assertIn(modname, coverage)
408409
self.assertEqual(coverage[modname], (5, 100))
409410

411+
def test_coverageresults_update(self):
412+
# Update empty CoverageResults with a non-empty infile.
413+
infile = TESTFN + '-infile'
414+
with open(infile, 'wb') as f:
415+
dump(({}, {}, {'caller': 1}), f, protocol=1)
416+
self.addCleanup(unlink, infile)
417+
results = trace.CoverageResults({}, {}, infile, {})
418+
self.assertEqual(results.callers, {'caller': 1})
419+
410420
### Tests that don't mess with sys.settrace and can be traced
411421
### themselves TODO: Skip tests that do mess with sys.settrace when
412422
### 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)