繁体   English   中英

tox 多项测试,重新使用 tox 环境

[英]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

想到了两种方法:

  1. 您可以将它们全部设置为使用相同的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
  1. 这实际上大致相同,但使用生成名称和特定于因子的命令使其更简洁(搜索 tox 配置文档页面以获取这些术语以获取更多信息)。 它还预先安装了所有的 deps:
[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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM