简体   繁体   English

如何让Travis CI安装在tests_require中声明的Python依赖项?

[英]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) 只需普通的需求文件即可满足您的需求(例如flake8pytest和其他依赖项)

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). 它在那里使用pbrcoveragecoverall的事实与我的答案无关(它有或没有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.

相关问题 指定在哪里安装distribute / setuptools包的'tests_require'依赖项 - Specifying where to install 'tests_require' dependencies of a distribute/setuptools package 如何在Travis CI中为python禁用一些测试 - How I can disable some tests in Travis CI for python 如何在Travis CI下安装Vowpal Wabbit Python绑定? - How to install Vowpal Wabbit Python bindings under Travis CI? 如何让 Travis CI 在 python 中使用 input()? - How can I make Travis CI use input() in python? 如何说服setuptools使用来自setup_require或tests_require的require包的临时目录? - How do I convince setuptools to use a temporary directory for requires packages from setup_require or tests_require? 为 Travis CI 提供备用 PyPI URL 以安装依赖项? - Provide alternate PyPI URL for Travis CI to install dependencies from? 让Travis-CI运行* Python 2和3 - Make Travis-CI run *both* Python 2 and 3 单元测试在python 2.6中崩溃(我正在使用Travis CI) - unit tests crashing in python 2.6 (i'm using Travis CI) 应该是pytest等。 进入tests_require []或extras_require {testing []}? - should pytest et al. go in tests_require[] or extras_require{testing[]}? 在Travis CI中缓存从源构建的依赖项是多么安全 - How safe is it to cache dependencies built from source in Travis CI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM