1

I've had a number of times where I've done the following:

#    code
m.   with open(somefile, modes) as data_interface:
..      ...
n.   ...

And then when trying to provide test coverage using python's coverage module it complains about missing a branch on the from the line where the 'with' is (line 'm') to the line after the block (line n).

I have yet to figure out how to get coverage to recognize the branch is not an issue. I eventually just go back to using the open() call without the context manager; but I would really prefer to keep using it within a context manager.

Ideas?

oz123
  • 27,559
  • 27
  • 125
  • 187
TemporalBeing
  • 311
  • 2
  • 6
  • I've never had problems getting code-coverage in my context managers... Where did you get coverage.py from? https://pypi.python.org/pypi/coverage What version are you using? – mgilson Mar 13 '15 at 18:55
  • 2
    This might be a known issue: https://bitbucket.org/ned/coveragepy/issue/146/context-managers-confuse-branch-coverage – mgilson Mar 13 '15 at 18:57
  • What version of python are you running? [This bug](https://bitbucket.org/ned/coveragepy/issue/319/invalid-coverage-report-when-using-2-with) seems to indicate that python2.7 might not be affected while python2.6 is. – mgilson Mar 13 '15 at 18:59
  • I have run into this bug in Py2 and Py3. in this case, I'm using latest Py 2.7 available on Ubuntu 14.04 LTS. – TemporalBeing Mar 16 '15 at 18:46
  • @mgilson that's exactly what I'm running into. Thanks. – TemporalBeing Mar 16 '15 at 21:22

0 Answers0