2015-11-28 30 views
5

python setup.py test Linting, test ve kapsam komutları yapmak için özel bir komut oluşturdum. Ancak, artık tests_require olarak belirtilen bağımlılıkları yüklemiyor. Her ikisini de aynı anda nasıl yapabilirim?Python setup.py özel test komutu için test bağımlılıkları

class TestCommand(setuptools.Command): 

    description = 'run linters, tests and create a coverage report' 
    user_options = [] 

    def initialize_options(self): 
     pass 

    def finalize_options(self): 
     pass 

    def run(self): 
     self._run(['pep8', 'package', 'test', 'setup.py']) 
     self._run(['py.test', '--cov=package', 'test']) 

    def _run(self, command): 
     try: 
      subprocess.check_call(command) 
     except subprocess.CalledProcessError as error: 
      print('Command failed with exit code', error.returncode) 
      sys.exit(error.returncode) 


def parse_requirements(filename): 
    with open(filename) as file_: 
     lines = map(lambda x: x.strip('\n'), file_.readlines()) 
    lines = filter(lambda x: x and not x.startswith('#'), lines) 
    return list(lines) 


if __name__ == '__main__': 
    setuptools.setup(
     # ... 
     tests_require=parse_requirements('requirements-test.txt'), 
     cmdclass={'test': TestCommand}, 
    ) 

cevap

3

Yanlış sınıftan miras alıyorsunuz. Kendisi setuptools.Command'un bir alt sınıfı olan setuptools.command.test.test'dan devralmayı deneyin, ancak bağımlılıklarınızın yüklenmesini yönetmek için ek yöntemler vardır. Daha sonra run() yerine run_tests() geçersiz kılmak isteyeceksiniz. Yani

, çizgisinde bir şey:

from setuptools.command.test import test as TestCommand 


class MyTestCommand(TestCommand): 

    description = 'run linters, tests and create a coverage report' 
    user_options = [] 

    def run_tests(self): 
     self._run(['pep8', 'package', 'test', 'setup.py']) 
     self._run(['py.test', '--cov=package', 'test']) 

    def _run(self, command): 
     try: 
      subprocess.check_call(command) 
     except subprocess.CalledProcessError as error: 
      print('Command failed with exit code', error.returncode) 
      sys.exit(error.returncode) 


if __name__ == '__main__': 
    setuptools.setup(
     # ... 
     tests_require=parse_requirements('requirements-test.txt'), 
     cmdclass={'test': MyTestCommand}, 
    )