修改并运行Doctest插件

问题描述 投票:0回答:1

我一直在成功使用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()])

如何使用插件激活文档测试?

python-3.x nose
1个回答
0
投票

此组合允许使用Doctestnose.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
© www.soinside.com 2019 - 2024. All rights reserved.