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