Poetry & Tox: Run tests in multiple python versions

Viewed 61

I run Poetry in combination together with tox for my unittests.

[tox]
skipsdist = True
envlist = autofix,linters,unittests
isolated_build = True


[testenv:unittests]
commands =
    poetry run pytest {posargs: {[pytest-config]posargs}}

I run the tests on my Jenkins Agent, which uses Python 3.9, but I also want to run my tests for Python 3.7 and 3.8.

Does anyone know how to do with Tox and Poetry?

I tried this:

envlist = autofix,linters,{py37,py38,py39}-unittests,pre-commit

but this results in:

C:\Users\xcg5847\Miniconda3\envs\testme\lib\site-packages\tox\config\__init__.py:670: UserWarning: conflicting basepython version (set 3.9, should be 3.7) for env 'py37-unittests';resolve conflict or set ignore_basepython
_conflict
1 Answers

There's a default section in tox, the [testenv] section. Note especially that this does not declare a name. This is the section that is run using the first available, or specifically selected, python executable.

Using the default section with envlist entry below should do the trick:

[tox]
skipsdist = True
envlist = py37,py38,autofix,linters
isolated_build = True

[testenv]
commands =
    poetry run pytest {posargs: {[pytest-config]posargs}}

And then tox will use py37 and py38 to run the [testenv] section. Assuming you have autofix,linters defined somewhere below.

Bonus:

Use a envlist = py,autofix,linters configuration. The py will select the first python executable on your PATH. Handy for working with coworkers. And then, in your CI, you can run a dedicated python executable with tox -e py38. Food for thought.

Source

Related