Issue #77 wontfix

Incorrect coverage results for python 3.0.1

memedough
created an issue

Hi,

I stumbled across what appears to be an edge case. Just thought I'd lodge it in case it's of interest.

I did the exact same test on python versions 246, 255, 265, 301 and 312. It only manifests on 301 and is easily repeatable with my tests.

The following code will cause the incorrect result:

{{{

import sys

def pytest_generate_tests(metafunc): for i in range(10): metafunc.addcall()

def test_foo(): version = sys.version_info[:2] if version == (2, 4): pass if version == (2, 5): pass if version == (2, 6): pass if version == (2, 7): pass if version == (3, 0): pass if version == (3, 1): pass }}}

It produce:

{{{ Name Stmts Miss Cover Missing


test_central 18 1 94% 18 }}}

Line 18 is the pass statement that it hits since it is python 301. If the pass statements are replaced by simple assignment like a = True then it works correctly and gives:

{{{ Name Stmts Miss Cover Missing


test_central 18 5 72% 10, 12, 14, 16, 20 }}}

Curious!

I'm using tip of coverage (3.4a1) plus my one minor fix to coverage (unrelated trivial change). But I see this problem before long time ago but only investigate it now (previously marked my tests to fail for python 301).

:)

Comments (3)

  1. Ned Batchelder repo owner

    Looking at this again, I wonder if the issue isn't Python 3.0.1, but the fact that the pass at the end could be optimized away. Add "if version == (4, 0): pass" to the end of the if-ladder, maybe Python 3.0.1 will work properly.

  2. Log in to comment