Covered branch inside finally block showing up as missing

Issue #623 closed
David MacIver created an issue

In some work I'm doing on Hypothesis, coverage is currently showing up some branches as missing that are covered.

Unfortunately I do not have a minimized reproduction. I tried a moderate amount and couldn't seem to trigger the behaviour in anything other than the actual example.

The following script will run a reproduction of this:

#!/usr/bin/env bash

git clone
cd hypothesis-python
git checkout db1db2719cd09cfe5c565967667aca05bf8ad615
virtualenv v
source v/bin/activate
pip install coverage attrs pytest-xdist
export PYTHONPATH=src
python -m coverage run  --branch --include=src/hypothesis/ -m pytest tests/cover/  -n 0 --ff
coverage report --rcfile=/dev/null --show-missing

You will see a lot of things missing here because this isn't the full set of tests for that file, but the notable ones are "811->829, 824->829". Both of these are definitely covered - if you add an "else assert False" to the if branches then that assert will fire in these tests - but the report shows them as missing branches.

I've tested this on both Python 2.7.13 and 3.6.0 and it seems to behave the same way in each.

NB: You may notice that this file does a bunch of messing around with coverage and tracing. All of that should be turned off by the HYPOTHESIS_INTERNAL_COVERAGE=true environment variable, so I'm reasonably sure that's not the culprit here.

Comments (2)

  1. David MacIver reporter

    For added confusingness, AFAICT the second but not the first of these two lines cannot be pragma-ed away! Adding a pragma: no branch to it causes it to still show up as an uncovered branch.

  2. Log in to comment