diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-03-03 09:50:45 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-03-03 09:50:45 -0500 |
commit | 365d7cb03d65ae5c830c3c97a2471478988695f1 (patch) | |
tree | b7e68dd71113ccc3bb185656fef8bc97595c3126 | |
parent | 5f9fd32139fd0c54d025bb4c8c4132cd07ee29b0 (diff) | |
download | python-coveragepy-git-365d7cb03d65ae5c830c3c97a2471478988695f1.tar.gz |
fix: protect fullcoverage against lineno=None, bpo46911
https://bugs.python.org/issue46911
-rw-r--r-- | coverage/collector.py | 3 | ||||
-rw-r--r-- | coverage/fullcoverage/encodings.py | 14 | ||||
-rw-r--r-- | tests/test_process.py | 4 |
3 files changed, 5 insertions, 16 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index 0397031a..0db8aba3 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -327,8 +327,7 @@ class Collector: self._collectors.append(self) # Replay all the events from fullcoverage into the new trace function. - for args in traces0: - (frame, event, arg), lineno = args + for (frame, event, arg), lineno in traces0: try: fn(frame, event, arg, lineno=lineno) except TypeError as ex: diff --git a/coverage/fullcoverage/encodings.py b/coverage/fullcoverage/encodings.py index b248bdbc..b8841866 100644 --- a/coverage/fullcoverage/encodings.py +++ b/coverage/fullcoverage/encodings.py @@ -35,20 +35,14 @@ class FullCoverageTracer: def fullcoverage_trace(self, *args): frame, event, arg = args - self.traces.append((args, frame.f_lineno)) + if frame.f_lineno is not None: + # https://bugs.python.org/issue46911 + self.traces.append((args, frame.f_lineno)) return self.fullcoverage_trace sys.settrace(FullCoverageTracer().fullcoverage_trace) -# In coverage/files.py is actual_filename(), which uses glob.glob. I don't -# understand why, but that use of glob borks everything if fullcoverage is in -# effect. So here we make an ugly hail-mary pass to switch off glob.glob over -# there. This means when using fullcoverage, Windows path names will not be -# their actual case. - -#sys.fullcoverage = True - -# Finally, remove our own directory from sys.path; remove ourselves from +# Remove our own directory from sys.path; remove ourselves from # sys.modules; and re-import "encodings", which will be the real package # this time. Note that the delete from sys.modules dictionary has to # happen last, since all of the symbols in this module will become None diff --git a/tests/test_process.py b/tests/test_process.py index 7558671b..eac3ddda 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -552,10 +552,6 @@ class ProcessTest(CoverageTest): @pytest.mark.expensive @pytest.mark.skipif(not env.C_TRACER, reason="fullcoverage only works with the C tracer.") @pytest.mark.skipif(env.METACOV, reason="Can't test fullcoverage when measuring ourselves") - @pytest.mark.xfail( - (3, 11, 0, "alpha", 4) <= env.PYVERSION, - reason="avoid 3.11 bug lineno==None: https://bugs.python.org/issue46389", - ) def test_fullcoverage(self): # fullcoverage is a trick to get stdlib modules measured from # the very beginning of the process. Here we import os and |