website/content/blog/pyenvtox.md

38 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2020-02-21 22:47:26 -05:00
---
2023-01-18 11:50:40 -05:00
title: "Testing your Python Application on Multiple Versions with Pyenv and Tox"
2020-02-21 22:47:26 -05:00
date: 2020-02-21T19:06:40-05:00
draft: false
2022-01-02 14:24:29 -05:00
tags: [ "Python", "Testing" ]
2023-01-05 14:04:45 -05:00
medium_enabled: true
2020-02-21 22:47:26 -05:00
---
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](https://blog.frank-mich.com/recipe-testing-multiple-python-versions-with-pyenv-and-tox/).
First make sure [pyenv is installed](https://github.com/pyenv/pyenv-installer). In the directory with your `setup.py` tell `pyenv` which python versions you want to consider.
```bash
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.
```bash
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..
```ini
[tox]
envlist =
py36
py37
py38
[testenv]
commands =
python3 -m unittest discover tests
```