~/Blog

Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI, Writer of Tidbits, and Linux Enthusiast

Testing your Python Application on Multiple Versions with Pyenv and Tox

Published on

Updated on

Warning: This post has not been modified for over 2 years. For technical posts, make sure that it is still relevant.

Pyenv is great for managing multiple python installations and tox is great for creating virtual environments for testing. What if we can combine the two? For more detailed information visit Frank-Mich’s Blog.

First make sure pyenv is installed. In the directory with your setup.py tell pyenv which python versions you want to consider.

pyenv local 3.6.0 3.7.0 3.8.0

Frank warns heavily not to specify multiple python versions with the same major.minor numbering. For example, 3.6.0 and 3.6.10 should not be included together.

Then install the tox package.

pip install tox

I made the mistake of making a virtual environment and then installing tox. That gets rid of the python version information we specified before.

Now specify a tox.ini with a structure similar to below..

[tox]
envlist = 
    py36
    py37
    py38

[testenv]
commands = 
    python3 -m unittest discover tests

Have any questions or want to chat: Reply via Email

Enjoyed this post?

Published a response to this? :