2015-11-28 11 views
5

Aby wykonać polecenia lintowania, testowania i pokrycia python setup.py test, utworzyłem niestandardowe polecenie. Jednak nie instaluje już zależności określonych jako tests_require. Jak mogę sprawić, aby obie prace były wykonywane w tym samym czasie?Pythonowe zależności testowania setup.py dla niestandardowego polecenia testowego

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}, 
    ) 

Odpowiedz

3

Odziedziczyłeś po niewłaściwej klasie. Spróbuj dziedziczyć po setuptools.command.test.test, która sama jest podklasą setuptools.Command, ale ma dodatkowe metody obsługi instalacji twoich zależności. Będziesz wtedy chciał zastąpić run_tests() zamiast run().

Tak, coś wzdłuż linii:

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}, 
    ) 
Powiązane problemy