[Python-checkins] gh-51524: Fix bug when calling trace.CoverageResults with valid infile (GH-99629)
miss-islington
webhook-mailer at python.org
Mon Nov 28 02:08:18 EST 2022
https://github.com/python/cpython/commit/345aaa41766d5ec2e34cf08beb79307caf5fc5cf
commit: 345aaa41766d5ec2e34cf08beb79307caf5fc5cf
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-11-27T23:08:12-08:00
summary:
gh-51524: Fix bug when calling trace.CoverageResults with valid infile (GH-99629)
(cherry picked from commit 594de165bf2f21d6b28eb17003ea78fc20c0ffed)
Co-authored-by: Furkan Onder <furkanonder at protonmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>
files:
A Misc/NEWS.d/next/Library/2022-11-21-17-56-18.gh-issue-51524.nTykx8.rst
M Lib/test/test_trace.py
M Lib/trace.py
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 75478557e787..3b3b2912798b 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -1,4 +1,5 @@
import os
+from pickle import dump
import sys
from test.support import captured_stdout
from test.support.os_helper import (TESTFN, rmtree, unlink)
@@ -407,6 +408,15 @@ def test_issue9936(self):
self.assertIn(modname, coverage)
self.assertEqual(coverage[modname], (5, 100))
+ def test_coverageresults_update(self):
+ # Update empty CoverageResults with a non-empty infile.
+ infile = TESTFN + '-infile'
+ with open(infile, 'wb') as f:
+ dump(({}, {}, {'caller': 1}), f, protocol=1)
+ self.addCleanup(unlink, infile)
+ results = trace.CoverageResults({}, {}, infile, {})
+ 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.
diff --git a/Lib/trace.py b/Lib/trace.py
index 2cf3643878d4..213e46517d68 100755
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -172,7 +172,7 @@ def __init__(self, counts=None, calledfuncs=None, infile=None,
try:
with open(self.infile, 'rb') as f:
counts, calledfuncs, callers = pickle.load(f)
- self.update(self.__class__(counts, calledfuncs, callers))
+ self.update(self.__class__(counts, calledfuncs, callers=callers))
except (OSError, EOFError, ValueError) as err:
print(("Skipping counts file %r: %s"
% (self.infile, err)), file=sys.stderr)
diff --git a/Misc/NEWS.d/next/Library/2022-11-21-17-56-18.gh-issue-51524.nTykx8.rst b/Misc/NEWS.d/next/Library/2022-11-21-17-56-18.gh-issue-51524.nTykx8.rst
new file mode 100644
index 000000000000..63fe7b8a3a32
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-11-21-17-56-18.gh-issue-51524.nTykx8.rst
@@ -0,0 +1 @@
+Fix bug when calling trace.CoverageResults with valid infile.
More information about the Python-checkins
mailing list