Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect coverage with branching and continue #496

Closed
nedbat opened this issue Jun 6, 2016 · 13 comments
Closed

Incorrect coverage with branching and continue #496

nedbat opened this issue Jun 6, 2016 · 13 comments
Labels
branch bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Jun 6, 2016

Originally reported by Eli Skeggs (Bitbucket: skeggse, GitHub: skeggse)


Here's a simple python script:

#!python

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


@nedbat
Copy link
Owner Author

nedbat commented Jun 6, 2016

Can you show what you mean by "bumped down a line"?

@nedbat
Copy link
Owner Author

nedbat commented Jun 6, 2016

Original comment by Eli Skeggs (Bitbucket: skeggse, GitHub: skeggse)


Sure:

#!python

up = iter('ta')

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

@nedbat
Copy link
Owner Author

nedbat commented Jun 6, 2016

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%

@nedbat
Copy link
Owner Author

nedbat commented Jun 6, 2016

Original comment by Eli Skeggs (Bitbucket: skeggse, GitHub: skeggse)


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

#!bash

$ 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

@nedbat
Copy link
Owner Author

nedbat commented Jun 6, 2016

Original comment by Eli Skeggs (Bitbucket: skeggse, GitHub: skeggse)


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.

@nedbat
Copy link
Owner Author

nedbat commented Jun 6, 2016

OK, I've reproduced it: Python 3.4 shows the missing branch, Python 2.7 does not.

@nedbat
Copy link
Owner Author

nedbat commented Dec 15, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: dachary)


The fix should be coordinated with #502 because it is in the same vicinity.

@nedbat
Copy link
Owner Author

nedbat commented Dec 15, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: 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.

@nedbat
Copy link
Owner Author

nedbat commented Dec 15, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: dachary)


For the record the proposed fix is at https://bitbucket.org/ned/coveragepy/pull-requests/104/arcs-from-continue-must-go-to_top-instead/diff

@nedbat
Copy link
Owner Author

nedbat commented Dec 19, 2016

Fix #496, while-true loop with a continue.

→ <<cset bd2f12dd55da (bb)>>

@nedbat
Copy link
Owner Author

nedbat commented Dec 19, 2016

Fixed in bd2f12dd55da (bb), which will be in version 4.3.

@nedbat
Copy link
Owner Author

nedbat commented Dec 19, 2016

BTW, the problem isn't about the "continue" being on the same line as the if. It's about a constant while condition (while True), and a continue statement.

@nedbat
Copy link
Owner Author

nedbat commented Dec 27, 2016

This fix was released as part of Coverage.py 4.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant