I am having a problem using tox. I have to say first that I am not an expert on virtual environments, and I prefer to use conda environments, I find them much more easy to use and understand.
So as the background of my system I have a Ubuntu 18 system, where Python is 3.6.9. I also have a conda environment where Python is 3.9.16, and an Anaconda base environment with Python 3.8.3
Anyway I want to use tox for testing with this tox.ini
file
[tox]
envlist=py37
skipsdist = True
[testenv]
deps=pytest
commands= pytest
After installing tox (and I installed it in both inside the conda environment and outside), when I ran tox
I got:
py37: skipped because could not find python interpreter with spec(s): py37
I get it, pytest 3.7 is not installed.
But I thought that is what virtual environments do… what is the point of me using tox if I have to install manually the version ?
And if I want to test it with multiple versions, do I have to install manually every version?
And what is more important, how can I install several versions?
With conda I have one version per environment.
How can I use tox efficiently here?
2
Answers
It’s not the version pytest which is wrong,
py37
refers to Python version 3.7, so it didn’t find the interpreter associated with it.You can install it in Ubuntu 18.04 by:
To use effectively tox you need to learn how to configure properly the
tox.ini
file and how the tox environments works. To start anypy3X
will execute the commands (usuallypytest
) in your main environment, usually defined astestenv
with the version 3.X of Python.Other tip is to use the flag
-p
for parallel execution of different environments, e.g.tox -p -e py37,py39
which will executetestenv
inpython3.7
andpython3.9
simultaneously.tox requires Python interpreters to already be installed beforehand. How the Python interpreters get installed is not tox‘s concern.
Some ideas to install multiple additional Python interpreters: