5
爲了製作python setup.py test
linting,測試和覆蓋命令,我創建了一個自定義命令。但是,它不再安裝指定爲tests_require
的依賴項。我怎樣才能讓兩者同時工作?Python setup.py自定義測試命令的測試依賴關係
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},
)