我一直在成功使用nose.run(argv=['--with-doctest'], addplugins=[...])
,但是现在我需要继承nose.plugins.doctests.Doctest
,以便可以修改其loadTestsFromModule
方法。我还有其他的插件(通过将nose.plugins.Plugin
子类化)正在运行,但是我没有成功运行doctests。
from nose.plugins.doctests import Doctest
class TestDocs(Doctest):
def loadTestsFromModule(self, module):
# add something here
super(testDocs, self).__init__(module)
我尝试了以下操作:
nose.run(addplugins=[TestDocs()])
nose.run(plugins=[TestDocs()])
nose.run(argv=['--with-testdocs'])
nose.run(argv=['--with-testdocs'], addplugins=[TestDocs()])
我还尝试了另一个名称,以防包括'test'在内的问题。而且我尝试直接使用DocTest
,但是如果不使用--with-doctest
就无法激活doctest。
nose.run(addplugins=[Doctest()])
nose.run(plugins=[Doctest()])
如何使用插件激活文档测试?
此组合允许使用Doctest
的nose.run
的自定义子类。
nose.run(argv=['--with-testdocs'], plugins=[TestDocs()])
使用argv=['--plugins']
很有帮助,因为它突出了plugins=
和addplugins=
之间的区别,因为我已经将addplugins用于其他插件。:
>>> nose.run(argv=['--with-testdocs'], plugins=[TestDocs()],
addplugins=[OtherPlugin(), AnotherPlugin()])
Plugin OtherPlugin
Plugin testdocs
Plugin AnotherPlugin