Wrong branch coverage on py 3.5

Issue #471 invalid
Ionel Cristian Mărieș
created an issue

This reproducer seems to cerate wrong results:

driver.py

import os
import sys

import coverage

master_cov = coverage.coverage(branch=True, data_suffix=True)
master_cov.erase()
master_cov.start()
import foo

master_cov.stop()
master_cov.save()
master_cov.report(show_missing=True)

foo.py

idx = 1

print("idx =", idx)

if idx == 0:
    pass
if idx == 1:
    pass

On 3.5.1 running python3.5 driver.py results is:

idx = 1
Name     Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------
foo.py       6      0      2      1    86%   7->-1

Shouldn't it be something like foo.py 6 0 2 1 86% 5->6?

Comments (7)

  1. Ned Batchelder repo owner

    Again, the driver is not needed. On Python 2.7, I get:

    Name     Stmts   Miss Branch BrPart  Cover   Missing
    ----------------------------------------------------
    foo.py       6      1      4      2    70%   6, 5->6, 7->-1
    

    on Python 3.5, I get:

    Name     Stmts   Miss Branch BrPart  Cover   Missing
    ----------------------------------------------------
    foo.py       5      0      2      1    86%   7->-1
    

    It looks like Python 3.5 optimizes away the "pass". I'll have to dig into it some more.

  2. Log in to comment