如何使用 Travis-CI 运行 Tox [英] How to run Tox with Travis-CI

查看:37
本文介绍了如何使用 Travis-CI 运行 Tox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 ToxTravis-CI?

我有一个 tox.ini:

[tox]
envlist = py{27,33,34,35}
recreate = True

[testenv]
basepython =
    py27: python2.7
    py33: python3.3
    py34: python3.4
    py35: python3.5
deps =
    -r{toxinidir}/pip-requirements.txt
    -r{toxinidir}/pip-requirements-test.txt
commands = py.test

它在多个 Python 版本中运行我的 Python 单元测试并完美运行.

which runs my Python unittests in several Python versions and works perfectly.

我想在 Travis-CI 中设置一个构建以在我将更改推送到 Github 时自动运行它,所以我有一个 .travis.yml:

I want to setup a build in Travis-CI to automatically run this when I push changes to Github, so I have a .travis.yml:

language: python
python:
-   "2.7"
-   "3.3"
-   "3.4"
-   "3.5"
install:
-   pip install tox
script:
-   tox

这在技术上似乎可行,但它在每个 Python 版本中重复运行我的所有测试......从每个 Python 版本.因此,一个需要 5 分钟的构建现在需要 45 分钟.

This technically seems to work, but it redundantly runs all my tests in each version of Python...from each version of Python. So a build that takes 5 minutes now takes 45 minutes.

我尝试从我的 yaml 文件中删除 python 列表,因此 Travis 将只运行一个 Python 实例,但这会导致我的 Python3.5 测试失败,因为找不到 3.5 解释器.显然,这是一个已知限制,因为 Travis-CI 不会安装 Python3.5 除非你在你的配置中指定那个确切的版本......但它不会为其他版本这样做.

I tried removing the python list from my yaml file, so Travis will only run a single Python instance, but that causes my Python3.5 tests to fail because the 3.5 interpreter can't be found. Apparently, that's a known limitation as Travis-CI won't install Python3.5 unless you specify that exact version in your config...but it doesn't do that for the other versions.

有什么办法可以解决这个问题吗?

Is there a way I can workaround this?

推荐答案

为此,我会考虑使用 tox-travis.这是一个允许使用 Travis CI 的多个 python 版本和 Tox 的完整可配置性的插件.为此,您将配置 .travis.yml 文件以使用 Python 进行测试:

For this I would consider using tox-travis. This is a plugin which allows use of Travis CI’s multiple python versions and Tox’s full configurability. To do this you will configure the .travis.yml file to test with Python:

sudo: false
language: python
python:
    - "2.7"
    - "3.4"
install: pip install tox-travis
script: tox

这将运行适当的测试环境,默认情况下,这些测试环境是任何以 py27 或 py34 作为名称因素的声明环境.如果没有与给定因素匹配的环境,将使用 Py27 或 py34 作为回退.

This will run the appropriate testenvs, which are any declared env with py27 or py34 as factors of the name by default. Py27 or py34 will be used as fallback if no environments match the given factor.

进一步阅读

这篇关于如何使用 Travis-CI 运行 Tox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆