简体   繁体   中英

How to test IPython magic with nosetests

I use nosetests for unit testing so as team, developing IPython. There are tests for built-in magic functions https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_magic.py

The problem is that writing tests as usual, when I try to initiate IPython with something like

from IPython import get_ipython
ip = get_ipython()
ip.register_magics(MyMagic)

nosetests fail with error that 'NoneType' object has no attribute 'register_magics' . This is because get_ipython() returns None .

In IPython tests some custom plugins solve the problem. Command iptest runs IPython tests, including magics. The problem is I don't understand how exactly should I run test, or where the plugin is located and how to modify it for custom magic testing. Any help will be appreciated

PS: I also tried to use InteractiveShellEmbed() , but it does not work as expected.

现在,这可以通过从终端调用来完成:

PYTHONPATH=<path/to/folder/with/test> iptest <file_with_tests_without_py>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM