mardi 3 mai 2016

How to run Tox with Travis-CI

How do you test different Python versions with Tox from within Travis-CI?

I have a 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

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

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

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.

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?

Aucun commentaire:

Enregistrer un commentaire