如何在`nosetests`命令中添加自定义鼻子插件

Ger*_*ard 5 python testing unit-testing nose nosetests

所以我在处理鼻子插件方面非常棒.

我一直在搜索很多,但关于鼻塞的文档似乎很少.我阅读并尝试了以下链接中的内容,尝试编写一个简单的鼻子插件并运行它nosetests,但没有成功:

  1. https://nose.readthedocs.org/en/latest/doc_tests/test_init_plugin/init_plugin.html
  2. https://nose.readthedocs.org/en/latest/plugins/writing.html

我不想编写自己的测试运行器或从任何其他脚本(通过run(argv=argv, suite=suite(), ...))运行测试,就像他们在第一个链接中一样.

我写了myplugin.py一个像这样的类的文件:

import os
from nose.plugins import Plugin

class MyCustomPlugin(Plugin):
    name = 'myplugin'

    def options(self, parser, env=os.environ):
        parser.add_option('--custom-path', action='store',
                          dest='custom_path', default=None,
                          help='Specify path to widget config file')

    def configure(self, options, conf):
        if options.custom_path:
            self.make_some_configs(options.custom_path)
            self.enabled = True

    def make_some_configs(self, path):
        # do some stuff based on the given path

    def begin(self):
        print 'Maybe print some useful stuff...'
        # do some more stuff
Run Code Online (Sandbox Code Playgroud)

并添加了setup.py这样的:

try:
    from setuptools import setup, find_packages
except ImportError:
    import distribute_setup
    distribute_setup.use_setuptools()
    from setuptools import setup, find_packages

setup(
    name='mypackage',
    ...
    install_requires=['nose==1.3.0'],
    py_modules=['myplugin'],
    entry_points={
      'nose.plugins.1.3.0': [
        'myplugin = myplugin:MyCustomPlugin'
      ]
    }
)
Run Code Online (Sandbox Code Playgroud)

两个文件都在同一目录中.

每次我跑nosetests --custom-path [path],我得到:

nosetests: error: no such option: --custom-path
Run Code Online (Sandbox Code Playgroud)

从上面提到的链接,我认为这是注册和启用自定义插件所需的全部内容.但看起来,无论是我做错了什么,还是鼻子的文档已经过时了.

有人可以指出我注册和启用插件的正确方法,我可以使用nosetests吗?

非常感谢!!:)

Sil*_*Ray 4

您不想要innose中的版本。按照文档所说的使用即可。入口点名称中的点版本与其说是版本,不如说是插件 API 版本。entry_pointssetup.pynose.plugins.0.10nose