[IPython-dev] Accessing get_ipython() within an embedded shell
Wes Turner
wes.turner at gmail.com
Tue Apr 10 02:22:12 EDT 2018
ipdb or pytest-ipdb may have a helpful example?
https://github.com/gotcha/ipdb/blob/master/ipdb/__main__.py
https://github.com/mverteuil/pytest-ipdb/blob/master/pytestipdb/ptipdb.py
These all require nose:
https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_magic_terminal.py
https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_magic_arguments.py
https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_interactiveshell.py
On Tuesday, April 10, 2018, Jacob Vanderplas <jakevdp at cs.washington.edu>
wrote:
> I'm trying to create automated tests for some magic functions within a
> pytest framework. I've figured out how to do part of what I need using an
> embedded interactive shell; briefly, I do something like this:
>
> from IPython.terminal.embed import InteractiveShellEmbed
> ipshell = InteractiveShellEmbed()
> out = ipshell.run_cell("%my_magic_command")
> assert out.result == expected_result
>
> The problem I encounter is that my magic function optionally uses IPython
> .get_ipython().user_ns to access variables in the user namespace, and
> IPython.get_ipython() returns None when run within an embedded shell in
> this way.
>
> Is there a way to create a simple embedded shell like this one that will
> behave as if it is an actual IPython shell, with IPython.get_ipython() def
> ined?
>
> Thanks,
>
> Jake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20180410/df69a6f2/attachment.html>
More information about the IPython-dev
mailing list