daino3
daino3

Reputation: 4566

IPython embed breakpoint - How can I see the code around the breakpoint?

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:

enter image description here

I would get something similar to ruby's PRY output like:

enter image description here

Upvotes: 1

Views: 792

Answers (1)

quazgar
quazgar

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

Related Questions