Reputation: 4566
Say I've got some python code with an embed
breakpoint like so:
from IPython import embed
def my_func(self):
some_var = 'awesome sauce'
embed()
# other stuff happens
when I run my test runner... with say pytest
:
$ python -m pytest -k test_something_awesome
How can my ipython terminal give me the contextual code around my embed breakpoint?
So instead of:
I would get something similar to ruby's PRY output like:
Upvotes: 1
Views: 792
Reputation: 4632
You can do this manually in IPython using the inspect
module:
import inspect
stack = inspect.stack(5) # 5 lines of context
print("".join(stack[11].code_context))
# For me, entries 0..10 are all IPython internals.
Upvotes: 0