zoukankan      html  css  js  c++  java
  • python nose测试框架全面介绍十三 ---怎么写nose插件

    之前有一篇文章介绍了自己写的插件 nose进度插件,但最近有朋友问我,看着nose的官方文档写的插件没用,下面再详细介绍一下

    一、准备

      1、新建一个文件夹,随便文件夹的名字,假设文件夹放在f://aa这里

      2、安装easy_install

    二、开始

    1、进入刚刚新建的文件夹f:/aa

    2、在该文件夹下新建一个文件,名字叫myplugin.py,内容如下:

    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...'

    3、再新建一个文件,文件名叫setup.py,内容如下:

    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没有自己写的插件,要用如下方式

    1、使用cmd,进入f:a
    2、输入easy_install .
    注意,上步最后有一个 .

    四、验证

    1、方式一:

    nosetests -p 查看,会看到下面这一行
    
    Plugin huplugin
      score: 100
      (no help available)
    
    
    说明安装成功

    2、方式二:

    nosetests -h查看
    
    --with-huplugin       Enable plugin MyCustomPlugin: (no help available)
                          [NOSE_WITH_HUPLUGIN]
    --custom-path=CUSTOM_PATH
                          Specify path to widget config file
    
    有上面这二个,说明安装成功
  • 相关阅读:
    Thinkphp中自己组合的数据怎样使用框架的分页
    CI框架不能有Index控制器
    购物车,修改数量错误
    TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement.
    OAuth2.0
    通过控制面板查看时间日志
    js再学习笔记
    Thinkphp验证码异步验证第二次及以后验证,验证错误----待解决
    cookie&&session再理解笔记
    markdown语法学习笔记
  • 原文地址:https://www.cnblogs.com/landhu/p/11497229.html
Copyright © 2011-2022 走看看