First, I've been a long-time user of coverage.py - thanks so much for creating it!
I recently have been working on a personal project of mine and uncovered a behavior with coverage.py that has me stumped.
Without going into too many gory details, my project is an extension to Python's pdb debugger that allows you to debug non-interactive Python programs over a telnet session. I've written some tests for it and am attempting to use coverage.py, but I can't get coverage.py to properly measure coverage even though I know certain lines of code are being hit in my tests.
It seems to come down to coverage.py seemingly not playing well with
pdb.set_trace(). Here's a very simple script that illustrates the problem I'm having:
import pdb class FriendlyPdb(pdb.Pdb): def cmdloop(self): print("Look, a custom pdb!") return pdb.Pdb.cmdloop(self) if __name__ == '__main__': FriendlyPdb().set_trace()
If I run this Python script, it behaves as you'd expect:
$ coverage run example.py --Return-- > /Users/ryanpetrello/example.py(11)<module>()->None -> FriendlyPdb().set_trace() Look, a custom pdb! (Pdb) c
Yet the coverage report says that lines 6-7 (the contents of the cmdloop function) are missing:
$ coverage report -m Name Stmts Miss Cover Missing ------------------------------------------ example.py 7 2 71% 6-7