[英]tox multiple tests, re-using tox environment
是否可以使用单个 tox 虚拟环境执行以下操作?
[tox]
envlist = test, pylint, flake8, mypy
skipsdist = true
[testenv:lint]
deps = pylint
commands = pylint .
[testenv:flake8]
deps = flake8
commands = flake8 .
[testenv:mypy]
commands = mypy . --strict
[testenv:test]
deps = pytest
commands = pytest
因为我只在我的 python 版本 (py3.7) 上进行测试,所以我不希望 tox 在它们运行时必须创建 4 个环境( .tox/test
、 .tox/pylint
、 .tox/flake8
、 .tox/mypy
)都可以在单一环境中运行。
我也想单独查看失败的原因,因此不想这样做:
[tox]
skipsdist = true
[testenv]
commands = pylint .
flake8 .
mypy . --strict
pytest
因为 output 会是这样的:
_____________ summary ___________
ERROR: python: commands failed
而不是这样:
____________________summary _________________
ERROR: test: commands failed
ERROR: lint: commands failed
ERROR: mypy: commands failed
test: commands succeeded
想到了两种方法:
envdir
以便在为测试环境连续“构建”virtualenv 时几乎不需要做任何工作:[testenv:lint]
envdir = {toxworkdir}/.work_env
deps = pylint
commands = pylint .
[testenv:flake8]
envdir = {toxworkdir}/.work_env
deps = flake8
commands = flake8 .
[testenv:mypy]
envdir = {toxworkdir}/.work_env
commands = mypy . --strict
[testenv:test]
envdir = {toxworkdir}/.work_env
deps = pytest
commands = pytest
[testenv:{lint,flake8,mypy,test}]
envdir = {toxworkdir}/.work_env
deps = pylint, flake8, pytest
commands =
lint: pylint .
flake8: flake8 .
mypy: mypy . --strict
test: pytest
tox
在第一个失败的命令处停止。 所以我的建议是从最快到最慢的顺序排列命令,然后让tox
完成剩下的工作:
[testenv]
commands =
flake8 .
pylint .
mypy . --strict
pytest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.