Python test.py setup.py dependencies for custom test team

To make the python setup.py test linting, testing and coverage commands, I created a custom command. However, it no longer installs the dependencies specified as tests_require . How can I make both work at the same time?

 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}, ) 
+5
source share
1 answer

Inherited from the wrong class. Try inheriting from setuptools.command.test.test , which itself is a subclass of setuptools.Command , but has additional methods for handling your dependencies. Then you want to override run_tests() , not run() .

So something like:

 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}, ) 
+3
source

Source: https://habr.com/ru/post/1237005/


All Articles