Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_trace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pickle
import sys
from test.support import captured_stdout
from test.support.os_helper import (TESTFN, rmtree, unlink)
Expand Down Expand Up @@ -412,6 +413,14 @@ def test_issue9936(self):
self.assertIn(modname, coverage)
self.assertEqual(coverage[modname], (5, 100))

def test_coverageresults_update(self):
outfile = TESTFN + '-outfile'
with open(outfile, 'wb') as f:
pickle.dump(({}, {}, {'caller': 1}), f, protocol=1)
self.addCleanup(unlink, outfile)
results = trace.CoverageResults({}, {}, outfile, {})
self.assertEqual(results.callers, {'caller': 1})

### Tests that don't mess with sys.settrace and can be traced
### themselves TODO: Skip tests that do mess with sys.settrace when
### regrtest is invoked with -T option.
Expand Down
4 changes: 2 additions & 2 deletions Lib/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ def __init__(self, counts=None, calledfuncs=None, infile=None,
self.callers = self.callers.copy()
self.infile = infile
self.outfile = outfile
if self.infile:
if self.infile is not None:
# Try to merge existing counts file.
try:
with open(self.infile, 'rb') as f:
counts, calledfuncs, callers = pickle.load(f)
self.update(self.__class__(counts, calledfuncs, callers))
self.update(CoverageResults(counts, calledfuncs, callers=callers))
except (OSError, EOFError, ValueError) as err:
print(("Skipping counts file %r: %s"
% (self.infile, err)), file=sys.stderr)
Expand Down