2013-11-21 5 views
5

私はノーズプラグインを扱うのに非常に戸惑います。カスタムノーズプラグインを `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 

をし、このような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' 
     ] 
    } 
) 

両方のファイルが同じディレクトリにあるし。

私はnosetests --custom-path [path]を実行するたびに、私が取得:

nosetests: error: no such option: --custom-path 

上記のリンクから、私はそれがカスタムプラグインを登録して有効にする必要があったことすべてだと思いました。 しかし、私は本当に間違っていることをしているか、または鼻の文書が古くなっているようです。

プラグインを登録して有効にする方法を教えてください。nosetestsと一緒に使用できますか?

ありがとうございます! :)

答えて

4

noseのバージョンをentry_pointsに入力すると、setup.pyになります。ドキュメントのようにnose.plugins.0.10を使用してください。エントリポイント名のドット付きバージョンは、プラグインAPIバージョンのバージョンではありません。noseです。

関連する問題