summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-03-12 08:31:12 -0400
committerNed Batchelder <ned@nedbatchelder.com>2023-03-12 11:46:25 -0400
commit8eb95b5ad2ed1cee1204b1ce95bad9118063d178 (patch)
treeb3849fe6cc9df4acdcf7006fe9b8d25a2047d10e
parentd276fa4f5a20dc3eb4dbf18bf4b8898fb3e24a79 (diff)
downloadpython-coveragepy-git-8eb95b5ad2ed1cee1204b1ce95bad9118063d178.tar.gz
fix: recent pypy3.9 now omits lines after jumps
We were seeing these failures in the nightly builds: ``` FAILED tests/test_arcs.py::LoopArcTest::test_continue - AssertionError: Possible arcs differ: minus is expected, plus is actual (-1, 1) # .1 (1, 2) # 12 (1, 5) # 15 (2, 3) # 23 (3, 1) # 31 - (4, 1) # 41 (5, -1) # 5. Missing arcs differ: minus is expected, plus is actual - (4, 1) # 41 + assert False FAILED tests/test_arcs.py::LoopArcTest::test_break - AssertionError: Possible arcs differ: minus is expected, plus is actual (-1, 1) # .1 (1, 2) # 12 (1, 5) # 15 (2, 3) # 23 (3, 5) # 35 - (4, 1) # 41 (5, -1) # 5. Missing arcs differ: minus is expected, plus is actual (1, 5) # 15 - (4, 1) # 41 assert False FAILED tests/test_arcs.py::ExceptionArcTest::test_raise_followed_by_statement - AssertionError: Possible arcs differ: minus is expected, plus is actual (-1, 1) # .1 (1, 2) # 12 (2, 3) # 23 (3, 4) # 34 (4, 6) # 46 - (5, 8) # 58 (6, 7) # 67 (7, 8) # 78 (8, -1) # 8. Missing arcs differ: minus is expected, plus is actual - (5, 8) # 58 + assert False FAILED tests/test_coverage.py::SimpleStatementTest::test_raise_followed_by_statement - AssertionError: [1, 2, 4, 5] != [1, 2, 3, 4, 5] assert [1, 2, 4, 5] == [1, 2, 3, 4, 5] At index 2 diff: 4 != 3 Right contains one more item: 5 Full diff: - [1, 2, 3, 4, 5] ? --- + [1, 2, 4, 5] FAILED tests/test_coverage.py::SimpleStatementTest::test_break - AssertionError: [1, 2, 3, 5] != [1, 2, 3, 4, 5] assert [1, 2, 3, 5] == [1, 2, 3, 4, 5] At index 3 diff: 5 != 4 Right contains one more item: 5 Full diff: - [1, 2, 3, 4, 5] ? --- + [1, 2, 3, 5] FAILED tests/test_coverage.py::SimpleStatementTest::test_continue - AssertionError: [1, 2, 3, 5] != [1, 2, 3, 4, 5] assert [1, 2, 3, 5] == [1, 2, 3, 4, 5] At index 3 diff: 5 != 4 Right contains one more item: 5 Full diff: - [1, 2, 3, 4, 5] ? --- + [1, 2, 3, 5] ```
-rw-r--r--coverage/env.py8
-rw-r--r--tests/test_coverage.py6
2 files changed, 10 insertions, 4 deletions
diff --git a/coverage/env.py b/coverage/env.py
index 5d69a234..b2229281 100644
--- a/coverage/env.py
+++ b/coverage/env.py
@@ -106,11 +106,17 @@ class PYBEHAVIOR:
# Lines after break/continue/return/raise are no longer compiled into the
# bytecode. They used to be marked as missing, now they aren't executable.
- omit_after_jump = pep626
+ omit_after_jump = (
+ pep626
+ or (PYPY and PYVERSION >= (3, 9) and PYPYVERSION >= (7, 3, 12))
+ )
# PyPy has always omitted statements after return.
omit_after_return = omit_after_jump or PYPY
+ # Optimize away unreachable try-else clauses.
+ optimize_unreachable_try_else = pep626
+
# Modules used to have firstlineno equal to the line number of the first
# real line of code. Now they always start at 1.
module_firstline_1 = pep626
diff --git a/tests/test_coverage.py b/tests/test_coverage.py
index 1992ebb8..1cade9cb 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -1121,7 +1121,7 @@ class CompoundStatementTest(CoverageTest):
)
def test_try_except_stranded_else(self) -> None:
- if env.PYBEHAVIOR.omit_after_jump:
+ if env.PYBEHAVIOR.optimize_unreachable_try_else:
# The else can't be reached because the try ends with a raise.
lines = [1,2,3,4,5,6,9]
missing = ""
@@ -1498,7 +1498,7 @@ class ExcludeTest(CoverageTest):
)
def test_excluding_try_except_stranded_else(self) -> None:
- if env.PYBEHAVIOR.omit_after_jump:
+ if env.PYBEHAVIOR.optimize_unreachable_try_else:
# The else can't be reached because the try ends with a raise.
arcz = ".1 12 23 34 45 56 69 9."
arcz_missing = ""
@@ -1801,7 +1801,7 @@ class Py25Test(CoverageTest):
)
def test_try_except_finally_stranded_else(self) -> None:
- if env.PYBEHAVIOR.omit_after_jump:
+ if env.PYBEHAVIOR.optimize_unreachable_try_else:
# The else can't be reached because the try ends with a raise.
lines = [1,2,3,4,5,6,10,11]
missing = ""