Skip to content

3.14: uncovered branch for loop completion with break #2168

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

Activity

  1. added
    bugSomething isn't working
    on May 6, 2026
  2. nedbat commented on Sep 21, 2026

    @nedbat
    Member

    Fixed in commit f653aae.

  3. nedbat commented on Sep 21, 2026

    @nedbat
    Member

    This may be related to: #1987

    This problem only occurs with the ctrace or pytrace cores. #1987 only occurs with the sysmon core, so they are unrelated.

  4. added a commit that references this issue on Sep 22, 2026
    f653aae
  5. nedbat commented on Sep 27, 2026

    @nedbat
    Member

    This is now released as part of coverage 7.16.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions