2012-04-11 3 views

答えて

2

testsというディレクトリにという名前のファンクションを定義した__init__.pyファイルが含まれているとします。

from setuptools import Command 
from setuptools import setup 

class run_tests(Command): 
    """Runs the test suite using the ``unittest2`` package instead of the  
    built-in ``unittest`` package.            

    This is necessary to override the default behavior of ``python setup.py 
    test``.                 

    """ 
    #: A brief description of the command.          
    description = "Run the test suite (using unittest2)." 

    #: Options which can be provided by the user.        
    user_options = [] 

    def initialize_options(self): 
     """Intentionally unimplemented.""" 
     pass 

    def finalize_options(self): 
     """Intentionally unimplemented.""" 
     pass 

    def run(self): 
     """Runs :func:`unittest2.main`, which runs the full test suite using 
     ``unittest2`` instead of the built-in :mod:`unittest` module.   

     """ 
     from unittest2 import main 
     # I don't know why this works. These arguments are undocumented.  
     return main(module='tests', defaultTest='suite', 
        argv=['tests.__init__']) 

setup(
    name='myproject', 
    ..., 
    cmd_class={'test': run_tests} 
) 

今すぐpython setup.py test実行私のカスタムtestのコマンドを実行している:

私のソリューションは、unittest2を使用して自分のtestコマンドでデフォルトpython setup.py testコマンドを交換することです。

+3

しかし、 'python setup.py test'は' setup() 'の' tests_require'リストから自動的にパッケージをインストールしないので、この解決法を使うと 'unittest2'を手動でインストールする必要があります。 – argentpepper

関連する問題