Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage.py doesn't seem to work with pdb.set_trace() #647

Closed
nedbat opened this issue Mar 1, 2018 · 3 comments
Closed

coverage.py doesn't seem to work with pdb.set_trace() #647

nedbat opened this issue Mar 1, 2018 · 3 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Mar 1, 2018

Originally reported by Anonymous


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:

#!python

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

@nedbat
Copy link
Owner Author

nedbat commented Mar 1, 2018

Original comment by ryanpetrello (Bitbucket: ryanpetrello, GitHub: ryanpetrello)


Apologies for creating this anonymously - I didn't realize Bitbucket allowed that. I'm the person who filed this issue.

@nedbat
Copy link
Owner Author

nedbat commented Mar 1, 2018

Both coverage.py and debuggers use the trace function feature. If everyone was careful to chain the trace functions, it might work, but I don't think pdb invokes a previous trace function in its function. I'm not sure coverage.py can do anything to make this work.

@nedbat
Copy link
Owner Author

nedbat commented Mar 2, 2018

Original comment by ryanpetrello (Bitbucket: ryanpetrello, GitHub: ryanpetrello)


Ned,

Thanks for taking the time to reply and confirming I wasn't missing something obvious. Please feel free to close this ticket :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant