[英]How to make Travis CI to install Python dependencies declared in tests_require?
I have Python package with setup.py
. 我有使用
setup.py
Python包。 It has regular dependencies declared in install_requires
and development dependencies declared in tests_require
, eg flake8
. 它具有在
install_requires
声明的常规依赖项和在tests_require
声明的开发依赖tests_require
,例如flake8
。
I thought pip install -e .
我认为
pip install -e .
or running python setup.py test
will also install my development dependencies and they'll be available. 或运行
python setup.py test
也将安装我的开发依赖项,它们将可用。 However, apparently they're not and I struggle to setup my Travis CI build right. 然而,显然他们不是,我很难设置我的Travis CI构建权。
install:
- "pip install -e ."
script:
- "python setup.py test"
- "flake8"
Build configured as above will fail, because flake8
will not be found as a valid command. 如上配置的构建将失败,因为将找不到
flake8
作为有效命令。 I also tried to invoke flake8
from inside of the python setup.py test
command (via subprocess
), but also without success. 我还尝试从
python setup.py test
命令(通过subprocess
flake8
内部调用flake8
,但也没有成功。
Also I hate the fact that flake8
can't be easily made integral part of the python setup.py test
command, but that's another story. 另外我讨厌
flake8
不能轻易成为python setup.py test
命令的组成部分这一事实,但这是另一个故事。
I prefer to keep most of the configuration in tox.ini
and rely on it to install and run what is to be run. 我更喜欢将大部分配置保留在
tox.ini
并依赖它来安装和运行要运行的内容。 For testing I use pytest
(the solution can be modified to use other testing frameworks easily). 为了测试我使用
pytest
(可以修改解决方案以轻松使用其他测试框架)。
Following files are used: 使用以下文件:
tox.ini
: automates the test tox.ini
:自动化测试 .travis.yml
: instructions for Travis .travis.yml
:特拉维斯的说明 setup.py
: installation script to install the package to test setup.py
:安装脚本以安装要测试的包 test_requirements.txt
: list of requirements for testing test_requirements.txt
:测试要求列表 tox.ini
[tox]
envlist = py{26,27,33,34}
[testenv]
commands =
py.test -sv tests []
deps =
-rtest-requirements.txt
.travis.yml
sudo: false
language: python
python:
- 2.6
- 2.7
- 3.3
- 3.4
install:
- pip install tox-travis
script:
- tox
test_requirements.txt
Just ordinary requirements file whith what ever you need in there (eg flake8
, pytest
and other dependencies) 只需普通的需求文件即可满足您的需求(例如
flake8
, pytest
和其他依赖项)
You may see sample at https://github.com/vlcinsky/awslogs/tree/pbr-setup.py 您可以在https://github.com/vlcinsky/awslogs/tree/pbr-setup.py上看到示例。
The fact it uses there pbr
, coverage
and coverall
is not relevant to my answer (it works with or without pbr). 它在那里使用
pbr
, coverage
和coverall
的事实与我的答案无关(它有或没有pbr)。
The more direct answer is that pip install
will not install tests_require
, intentionally separating runtime requirements from test requirements. 更直接的答案是
pip install
不会安装tests_require
,故意将运行时需求与测试要求分开。 python setup.py test
creates a virtualenv-like environment to run the tests in, un-doing this afterwards. python setup.py test
创建一个类似virtualenv的环境来运行测试,之后不再执行此操作。 flake8
is thus unavailable once it is done. 因此,一旦完成,
flake8
可用了。
Flake8 has setuptools integration and also integrates with pytest if you use that. Flake8具有setuptools集成 功能,如果您使用它,还可以与pytest集成 。 pytest itself also integrates with setuptools .
pytest本身也与setuptools集成 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.