diff options
author | 2022-11-27 23:15:00 -0800 | |
---|---|---|
committer | 2022-11-27 23:15:00 -0800 | |
commit | fce9516a0f81fa4973907f73b6f4718d7a67d99e (patch) | |
tree | ede6da40a885b80930672de3eced87affe4a5472 | |
parent | Docs: both sqlite3 "point examples" now adapt to str (GH-99823) (diff) | |
download | cpython-fce9516a0f81fa4973907f73b6f4718d7a67d99e.tar.gz cpython-fce9516a0f81fa4973907f73b6f4718d7a67d99e.tar.bz2 cpython-fce9516a0f81fa4973907f73b6f4718d7a67d99e.zip |
gh-51524: Fix bug when calling trace.CoverageResults with valid infile (GH-99629)
(cherry picked from commit 594de165bf2f21d6b28eb17003ea78fc20c0ffed)
Co-authored-by: Furkan Onder <furkanonder@protonmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
-rw-r--r-- | Lib/test/test_trace.py | 10 | ||||
-rwxr-xr-x | Lib/trace.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-11-21-17-56-18.gh-issue-51524.nTykx8.rst | 1 |
3 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py index 5f712111ca..fad2b3b837 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) @@ -412,6 +413,15 @@ class TestCoverage(unittest.TestCase): 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 2cf3643878..213e46517d 100755 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -172,7 +172,7 @@ class CoverageResults: 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 0000000000..63fe7b8a3a --- /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. |