以前有一篇文章介绍了本身写的插件 nose进度插件,但最近有朋友问我,看着nose的官方文档写的插件没用,下面再详细介绍一下html
一、新建一个文件夹,随便文件夹的名字,假设文件夹放在f://aa这里python
二、安装easy_installspa
一、进入刚刚新建的文件夹f:/aa插件
二、在该文件夹下新建一个文件,名字叫myplugin.py,内容以下:code
import os from nose.plugins import Plugin class MyCustomPlugin(Plugin): name = 'huplugin' def options(self, parser, env=os.environ):
Plugin.options(self, parser, env) 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): pass # do some stuff based on the given path def begin(self): print 'Maybe print some useful stuff...'
三、再新建一个文件,文件名叫setup.py,内容以下:htm
import sys try: import ez_setup ez_setup.use_setuptools() except ImportError: pass from setuptools import setup setup( name='mypackage', version='0.1', entry_points={ 'nose.plugins.0.1.0': [ 'myplugin = myplugin:MyCustomPlugin' ] } )
这里要注意了,若是直接使用python setup.py install的话,能够安装成功,但nosetests -h没有本身写的插件,要用以下方式blog
1、使用cmd,进入f:\a 2、输入easy_install . 注意,上步最后有一个 .
一、方式一:ci
nosetests -p 查看,会看到下面这一行 Plugin huplugin score: 100 (no help available) 说明安装成功
二、方式二:文档
nosetests -h查看 --with-huplugin Enable plugin MyCustomPlugin: (no help available) [NOSE_WITH_HUPLUGIN] --custom-path=CUSTOM_PATH Specify path to widget config file 有上面这二个,说明安装成功