<div dir="ltr">Wes,<div>Thanks for the links! I found the clue I needed in the pytest-ipdb link.</div><div><br></div><div>Instead of using:</div><div><br></div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">  from<span> </span><span class="gmail-m_-3560420487135173310gmail-il"><span class="gmail-il">IPython</span></span>.terminal.embed import InteractiveShellEmbed</font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">  ipshell = InteractiveShellEmbed()</font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace"><br></font></div><div style="color:rgb(34,34,34);font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="arial, helvetica, sans-serif">I used this:</font></div><div style="text-align:start;text-indent:0px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:12.8px"><div style="font-family:arial,helvetica,sans-serif"><br></div><div style=""><font face="monospace, monospace">  from IPython import InteractiveShell</font></div><div style=""><font face="monospace, monospace">  ipshell = InteractiveShell.instance()</font></div></span></div><div style="color:rgb(34,34,34);font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="arial, helvetica, sans-serif">And now calls to IPython.get_ipython() within the shell work properly.</font></div><div style="color:rgb(34,34,34);font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="arial, helvetica, sans-serif">Thanks,</font></div><div style="color:rgb(34,34,34);font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font face="arial, helvetica, sans-serif">    Jake</font></div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"> <font size="1">Jake VanderPlas</font></div><div dir="ltr"><font size="1"> Senior Data Science Fellow</font></div><div dir="ltr"><span style="font-size:x-small"> Director of Open Software</span><div><div><font size="1"> </font><span style="font-size:x-small">University of Washington </span><span style="font-size:x-small">eScience Institute<br></span></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Tue, Apr 10, 2018 at 2:22 AM, Wes Turner <span dir="ltr"><<a href="mailto:wes.turner@gmail.com" target="_blank">wes.turner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>ipdb or pytest-ipdb may have a helpful example?</div><div><br></div><a href="https://github.com/gotcha/ipdb/blob/master/ipdb/__main__.py" target="_blank">https://github.com/gotcha/<wbr>ipdb/blob/master/ipdb/__main__<wbr>.py</a><div><br></div><div><a href="https://github.com/mverteuil/pytest-ipdb/blob/master/pytestipdb/ptipdb.py" target="_blank">https://github.com/mverteuil/<wbr>pytest-ipdb/blob/master/<wbr>pytestipdb/ptipdb.py</a></div><div><br></div><div>These all require nose:</div><div><br></div><div><a href="https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_magic_terminal.py" target="_blank">https://github.com/ipython/<wbr>ipython/blob/master/IPython/<wbr>core/tests/test_magic_<wbr>terminal.py</a></div><div><br></div><div><a href="https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_magic_arguments.py" target="_blank">https://github.com/ipython/<wbr>ipython/blob/master/IPython/<wbr>core/tests/test_magic_<wbr>arguments.py</a></div><div><br></div><div><a href="https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_interactiveshell.py" target="_blank">https://github.com/ipython/<wbr>ipython/blob/master/IPython/<wbr>core/tests/test_<wbr>interactiveshell.py</a><div><div class="h5"><br><br>On Tuesday, April 10, 2018, Jacob Vanderplas <<a href="mailto:jakevdp@cs.washington.edu" target="_blank">jakevdp@cs.washington.edu</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><span style="font-size:12.8px">I'm trying to create automated tests for some magic functions within a pytest framework</span><span style="font-size:12.8px">. I've figured out how to do part of what I need using an embedded interactive shell; briefly, I do something like this:</span></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><div><font face="monospace, monospace">from<span> </span><span>IPython</span>.terminal.embed import InteractiveShellEmbed</font></div><div><font face="monospace, monospace">ipshell = InteractiveShellEmbed()</font></div><div><font face="monospace, monospace">out = ipshell.run_cell("%my_magic_co<wbr>mmand")</font></div><div><font face="monospace, monospace">assert out.result == expected_result</font></div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><font face="monospace, monospace"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif">The problem I encounter is that my magic function optionally uses </font><font face="monospace, monospace"><span>IPython</span>.get_ipython().use<wbr>r_ns</font><font face="arial, helvetica, sans-serif"><span> </span>to access variables in the user namespace, and<span> </span></font><font face="monospace, monospace"><span>IPython</span>.get_ipython()</font><font face="arial, helvetica, sans-serif"><span> </span>retu<wbr>rns<span> </span></font><font face="monospace, monospace">None </font><font face="arial, helvetica, sans-serif">when run within an embedded shell in this way.</font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif">Is there a way to create a simple embedded shell like this one that will behave as if it is an actual<span> </span><span>IPython</span><span> </span>shell, with<span> </span></font><font face="monospace, monospace"><span>IPython</span>.get_ipython()</font><font face="arial, helvetica, sans-serif"><span> </span>def<wbr>ined?</font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif">Thanks,</font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif">  Jake</font></div></div>
</div>
</blockquote></div></div></div>
<br>______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@python.org">IPython-dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/ipython-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br></div>