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
Travis provides the python version for each test as TRAVIS_PYTHON_VERSION
, but in the form '3.4'
, while tox
expects 'py34'
.
If you don't want to rely on an external lib (tox-travis) to do the translation, you can do that manually:
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
install:
- pip install tox
script:
- tox -e $(echo py$TRAVIS_PYTHON_VERSION | tr -d .)
Search this pattern in a search engine and you'll find many projects using it.
This works for pypy as well:
tox -e $(echo py$TRAVIS_PYTHON_VERSION | tr -d . | sed -e 's/pypypy/pypy/')
Source: flask-mongoengine's .travis.yml.