Skip to content

3.14: uncovered branch for loop completion with break #2168

@bfis

Description

@bfis

Describe the bug
In python 3.14 there is a uncovered branch detected in for loops that have a conditional break and a statement thereafter, when using COVERAGE_CORE=ctrace.

To Reproduce

def foo(*x):
    for i in x:
        if i:
            break
    pass


foo()
foo(0)
foo(1)

The coverage shows for line 2: line 2 didn't jump to line 5 because the loop on line 2 didn't complete

Versions:

  • CPython: 3.14.4
  • coverage: 7.13.5
  • pytest: 9.0.3
  • pytest-cov: 7.1.0

Expected behavior
The line should be considered covered, since e.g. foo(0) will exhaust the loop.
It works correctly if:

  • using CPython 3.13.3
  • using COVERAGE_CORE=sysmon (or no override)
  • if there is a statement after the if within the for loop
  • if there is no statement after the for loop
  • if the for loop has an else branch

Additional context
This may be related to: #1987

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions