简体   繁体   English

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

[英]tox multiple tests, re-using tox environment

Is it possible to do the following using a single tox virtual 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


As I am only testing on my python version (py3.7), I don't want tox to have to create 4 environments ( .tox/test , .tox/pylint , .tox/flake8 , .tox/mypy ) when they could all be run on a single environment.因为我只在我的 python 版本 (py3.7) 上进行测试,所以我不希望 tox 在它们运行时必须创建 4 个环境( .tox/test.tox/pylint.tox/flake8.tox/mypy )都可以在单一环境中运行。

I also want to see what failed individually individually, thus don't want to do:我也想单独查看失败的原因,因此不想这样做:

[tox]
skipsdist = true

[testenv]
commands = pylint .
           flake8 .
           mypy . --strict
           pytest

as the output would be like this:因为 output 会是这样的:

_____________ summary ___________
ERROR:   python: commands failed

and not like this:而不是这样:

____________________summary _________________
ERROR:   test: commands failed
ERROR:   lint: commands failed
ERROR:   mypy: commands failed
  test: commands succeeded

Two approaches come to mind:想到了两种方法:

  1. You can set them all to use the same envdir so that there's little work to be done when "building" the virtualenv for the test environments successively:您可以将它们全部设置为使用相同的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. This is really about the same, but using generative names and factor-specific commands to make it more concise (search the tox configuration doc page for those terms for more info).这实际上大致相同,但使用生成名称和特定于因子的命令使其更简洁(搜索 tox 配置文档页面以获取这些术语以获取更多信息)。 It also installs all of the deps up front:它还预先安装了所有的 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 stops at the first failed command. tox在第一个失败的命令处停止。 So my recommendation is to order commands from fasterst to slowest and allow tox to do the rest:所以我的建议是从最快到最慢的顺序排列命令,然后让tox完成剩下的工作:

[testenv]
commands =
    flake8 .
    pylint .
    mypy . --strict
    pytest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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