2016-10-19 12 views
6

は、この機能を有効にするには、パッケージがあるようですが、私は、Python 3.5.2にそれで運を持っていない、または2.7.12:jupyterのセル関数でpython doctestを実行できますか?

from ipython_doctester import test 

@test 
def my_fun(): 
    ''' 
    >>> 2 + 3 
    6 
    ''' 
    pass 

TypeError: data must be a dict, got: 'ipython_doctester' 

それが使用してjupyter細胞からdoctestを実行することが可能ですこのパッケージまたは何か他の方法?

私も%doctest_modeを見ました。Doctestモードをオン/オフしても、実際のDoctestをセルから実行できませんでした。

答えて

6

Jupyterノートパソコンでこれを試してみてください:

def my_fun(): 
    ''' 
    >>> 2 + 3 
    6 
    ''' 
    pass 

import doctest 
doctest.testmod() 

結果は次のようになります。

********************************************************************** 
File "__main__", line 3, in __main__.my_fun 
Failed example: 
    2 + 3 
Expected: 
    6 
Got: 
    5 
********************************************************************** 
1 items had failures: 
    1 of 1 in __main__.my_fun 
***Test Failed*** 1 failures. 
TestResults(failed=1, attempted=3) 

(私はpythonの2.7.12を使用)

+0

でも、Python 3.5でも動作します。 – josh

0

私はこのページを打つ保つが、望みました単一の関数のテストを実行します。この場合、回答はhttps://stackoverflow.com/a/10081450/741316になります。すなわち:

def my_fun(): 
    ''' 
    >>> 2 + 3 
    6 
    ''' 
    pass 

import doctest 
doctest.run_docstring_examples(my_fun, globals()) 
関連する問題