My tox environment

My tox environment

Published Nov. 7, 2015 in Tests and quality - Last update on Nov. 18, 2015.

I have long refused to use tox in my Python projects, I though to test code against multiple version Python was a task which should be made by CI tools. After contribute to several projects, I learned to appreciate it when I want to test code with different aspects. I was wrong and for me it should be considered as the first way to build a project for the following topics:

  • Creates a clean and isolated environment, useful for dirty VM like mine
  • Can run on all available Python versions including PyPy
  • Supports jobs matrix
  • Manages dependencies

My usecase

My blog is designed as cloud-native so I try make more agnostic as possible, it should support Python 2.7 and >=3.2, Django >= 1.7 and the maximum of database backend. My tox configuration must be a matrix of all this components with some pitfalls: MySQL drivers are not the same in Python 2 & 3 or PyPy must have pure Python dependencies.

Nothing more simple with Tox:

envlist = py{2.6,2.7,pypy,3.2,3.3,3.4,3.5}-django{1.7,1.8}-{sqlite,mysql,postgresql}

passenv = *
basepython =
    py2.6: python2.6
    py2.7: python2.7
    pypypy: pypy
    py3.2: python3.2
    py3.3: python3.3
    py3.4: python3.4
    py3.5: python3.5
deps =
    django1.7: Django>=1.7,>1.8
    django1.8: Django>=1.8,>1.9
    postgresql: psycopg2<=2.4.5
    mysql: mysqlclient
commands = {posargs:coverage run {toxinidir}/myblog/ test}

Links and references


Post your comment

Comment as . Log out.