gotcha / ipdb

Integration of IPython pdb
BSD 3-Clause "New" or "Revised" License
1.85k stars 146 forks source link

`-m` with ipdb? #192

Closed MrMino closed 4 years ago

MrMino commented 4 years ago

I don't know whether this request should be pointed at pdb rather than ipdb, ~but since chances of having this feature implemented any time soon by python core devs is probably close to nil,~ here goes:

Taken from man python:

      -m module-name
             Searches sys.path for the named module and runs the corresponding .py file as a script.

This can be used to run unittests:

python -m unittest discover

Sometimes when tests fail, in order to run a post mortem on them, I have to manually find the failing testcase, add import ipdb; ipdb.set_trace() to it, rerun the thing, c, Enter... only to find out that I added the set_trace() in the wrong line.

I'd like to kindly request that the -m be added to ipdb with the same semantics as the interpreter option.

This will make it very simple to debug testcases:

ipdb -m unittest discover

c, Enter Traceback... ddddd... until the bottom frame profit

MrMino commented 4 years ago

but since chances of having this feature implemented any time soon by python core devs is probably close to nil, here goes:

Scratch that. https://docs.python.org/3/library/pdb.html:

New in version 3.7: pdb.py now accepts a -m option that execute modules similar to the way python3 -m does. As with a script, the debugger will pause execution just before the first line of the module.

I think I might be able to PR this.

MrMino commented 4 years ago

Hey, @gotcha, pretty please :)? I know you're probably seriously busy, and your todo-list is as long as your arm and a leg - understandable. This is a simple, 20 line merge request which was done by analogy to what's already implemented in pdb - nothing fancy there, and it adds a really cool feature. I'd love to use it on machines at work where we install ipdb automatically, without having to resort to patching it up every time.

MrMino commented 4 years ago

This has been released in v0.13.4, see linked PR.