pytest-cov icon indicating copy to clipboard operation
pytest-cov copied to clipboard

Code block reported missing when provably covered

Open al-niessner opened this issue 7 years ago • 19 comments

It appears as though code covered with pytest is being reported as missing. While it may be a bug in pytest-cov, it may also be a problem with configuration. The configuration is quite simple and is all on the command line -- configuration files are avoided.

Here are the platform details:

$ uname -a
Linux 4.10.0-27-generic #30~16.04.2-Ubuntu SMP Thu Jun 29 16:07:46 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ pytest --version
This is pytest version 3.1.3, imported from /usr/local/lib/python3.5/dist-packages/pytest.py
setuptools registered plugins:
  pytest-cov-2.5.1 at /usr/local/lib/python3.5/dist-packages/pytest_cov/plugin.py
$ python3 -m pytest --cov=pix --cov=pixg --cov=pge --cov-branch --cov-report term-missing -v test

If I then run the unit tests, it completes without error and the line that concerns me is:

----------- coverage: platform linux, python 3.5.2-final-0 -----------
Name                         Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------
pix/complete.py                 91      5     55      9    89%   40-47, 71, 32->37, 49->exit, 61->78, 64->76, 66->73, 68->71, 95->106, 99->103, 136->143

The block of code 136-143 is:

                if not all (same.values()):
                    _error ('Reservoir "' + no.name + '" does not match ' +
                            'node "' + f.node + '".\n   ' +
                            '\n   '.join (['{} : {}'.format (k, same[k])
                                           for k in sorted (same)]))
                    result = pix.RuleStatus.fail
                    pass

This block is covered with same.values() all being true and with some false elements. This can be shown by forcing pytest with assert to fail and looking at the output:

starting rule 03
completed rule 03
rule_03 completed with the status: good
starting rule 03
Reservoir "/fred" does not match node "/sally".
   type : False
completed rule 03
rule_03 completed with the status: fail
starting rule 03
Reservoir "/fred" does not match node "/sally".
   type : False
completed rule 03
rule_03 completed with the status: fail
starting rule 03
Reservoir "/fred" does not match node "/sally".
   length : False
   shape : True
   type : True
completed rule 03
rule_03 completed with the status: fail
starting rule 03
Reservoir "/fred" does not match node "/sally".
   length : True
   shape : False
   type : True
completed rule 03
rule_03 completed with the status: fail
starting rule 03
completed rule 03
rule_03 completed with the status: good

While the messages is bit to consume all at once, the important bit is to notice that the block being reported as missing is generating the fail message. I included the good messages to show that they same block is called when all (same.values()) is both True and False.

Hence, I think this shows that the block is being reported as missing when it is provably being executed. I cannot post all of the code for someone in this group to test, but with some help I am willing to work through the pytest-cov code to help find and isolate the problem (looking for hints as how and where to start). With the best of luck someone will recognize that I did not type my command line correctly.

al-niessner avatar Aug 01 '17 15:08 al-niessner