使用nose.main运行doctest插件
我想在Python中运行Nose内置的使用nose.main运行doctest插件,nose,python-nose,Nose,Python Nose,我想在Python中运行Nose内置的Doctest插件,尤其是在没有命令行选项或环境变量的情况下 人们预计以下措施将起作用: import nose, os from nose.plugins.builtin import Doctest # or from nose.plugins.doctests import Doctest plugins = [Doctest(),] nose.main(addplugins=plugins) # or nose.main(plugins=plug
Doctest
插件,尤其是在没有命令行选项或环境变量的情况下
人们预计以下措施将起作用:
import nose, os
from nose.plugins.builtin import Doctest
# or from nose.plugins.doctests import Doctest
plugins = [Doctest(),]
nose.main(addplugins=plugins)
# or nose.main(plugins=plugins)
然而,上面的代码似乎并没有像预期的那样加载Doctest插件
我的想法和意见将不胜感激。以下是我所做的:
import nose
argv = sys.argv[:]
argv.insert(1, "--with-doctest")
nose.main(argv=argv)
它没有我想要的那么干净,但它可以工作。基于Brian的解决方案,为了启动交互式会话中的所有内容,还可以执行以下操作:
import nose
nose.run(argv=['', '--with-doctest']) # first empty item is ignored by nose.run
但您的解决方案更适合于直接从命令行启动的脚本,可能还有其他选项