Testing in different environments

One option would be to to use tox if you would like to run the test sequentially on two (or more) Python versions. Some customers have reported success with the following configuration:

tox.ini

[tox]
envlist = py26,py34
[testenv]
commands=pip install -e .
         pip install -r requirements-dev.txt 
         python setup.py test 
install_command=pip install --process-dependency-links --allow-external --allow-unverified {opts} {packages}

circle.yml

dependencies:
   pre:
     - pip install tox

test:
   override:
     - tox

Another option would be to simply change the Python version, either during the build or on one of the containers in a parallel build. We use pyenv to manage Python versions, so you could do something like this if you are using a single container:

machine:
  python:
    version: 2.6.8
​
test:
  override:
    - make test
    - pyenv global 2.7.9
    - make test

Alternatively, you can test both versions in parallel—e.g. set up a parallel build and make a few build containers run different versions of Python.

We add an env var called $CIRCLE_NODE_INDEX when a build runs with more than one container. This means that you can just make the Python choice with a simple if condition in the dependencies: pre step. Mind that the machine section cannot handle multiple configurations, so you could do something like this:

machine:
  python:
    version: 2.6.8
​
dependencies:
  pre:
    - if [ $CIRCLE_NODE_INDEX == "1" ] ; then pyenv global 2.7.9 ; fi
​
test:
  override:
    - make test: # note the colon
        parallel: true


This will configure Python 2.7.9 instead of 2.6.8 only on the second container (index starts at 0).

1 Like