Poetry & Tox:在多个python版本中运行测试



我将Poetry与tox组合用于单元测试。

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

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

我在Jenkins Agent上运行测试,它使用Python 3.9,但我也想运行Python 3.7和3.8的测试。

有人知道如何处理Tox和Poetry吗?

我试过这个:

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

但这会导致:

C:Usersxcg5847Miniconda3envstestmelibsite-packagestoxconfig__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

tox中有一个默认部分,即[testenv]部分。请特别注意,这并不是声明名称。这是使用第一个可用或特别选择的python可执行文件运行的部分。

使用下面带有envlist条目的默认部分应该可以做到这一点:

[tox]
skipsdist = True
envlist = py37,py38,autofix,linters
isolated_build = True
[testenv]
commands =
poetry run pytest {posargs: {[pytest-config]posargs}}

然后tox将使用py37和py38来运行[testenv]部分。假设你有自动修补,门楣定义在下面的某个地方。

奖金:

使用envlist = py,autofix,linters配置。py将选择PATH上的第一个python可执行文件。方便与同事一起工作。然后,在您的CI中,您可以使用tox -e py38运行一个专用的python可执行文件。值得思考。

最新更新