Incorrect coverage with branching and continue

Issue #496 resolved
Eli Skeggs
created an issue

Here's a simple python script:

up = iter('ta')

while True:
  char = next(up)
  if char == 't': continue
  break

The html coverage resulting from both coverage run --branch example.py or coverage run --branch --timid example.py, reports that the continue statement was never executed. If the continue statement is bumped down a line, it works as expected.

coverage --version reports version 4.1 with C extension

Comments (16)

  1. Ned Batchelder repo owner

    I tried reproducing your problem, but I see 100% coverage:

    $ cat bug496.py
    up = iter('ta')
    
    while True:
      char = next(up)
      if char == 't': continue
      break
    $ coverage run --branch bug496.py
    $ coverage report -m
    Name        Stmts   Miss Branch BrPart  Cover   Missing
    -------------------------------------------------------
    bug496.py       5      0      4      0   100%
    
  2. Eli Skeggs reporter

    So it's an environment issue, I guess? What would impact this?

    I'm running Python 3.5.1, on Arch Linux 4.5.3-1-ARCH

    $ cat example.py 
    up = iter('ta')
    
    while True:
      char = next(up)
      if char == 't': continue
      break
    $ coverage run --branch example.py 
    $ coverage report -m
    Name         Stmts   Miss Branch BrPart  Cover   Missing
    --------------------------------------------------------
    example.py       5      0      2      1    86%   5->3
    
  3. Eli Skeggs reporter

    I'm able to reproduce on a hosted Ubuntu VM running Python 3.4.3 (it also has 2.7 installed, and if I install Coverage.py with pip2, I can't reproduce the issue). I sent you some instructions on getting quick access to said VM.

  4. Loic Dachary

    This probably happens because process_continue_exits fails to take into account that the first line of the while is the first line of the body when the condition is a constant in python-3.

  5. Log in to comment