是否可以使用单个 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
Run Code Online (Sandbox Code Playgroud)
由于我只在我的 python 版本 (py3.7) 上进行测试,因此我不希望 tox 必须创建 4 个环境(.tox/test、.tox/pylint、.tox/flake8、.tox/mypy),因为它们都可以在单个环境上运行。
我还想查看单独失败的内容,因此不想这样做:
[tox]
skipsdist = true
[testenv]
commands = pylint .
flake8 .
mypy . --strict
pytest
Run Code Online (Sandbox Code Playgroud)
因为输出会是这样的:
_____________ summary ___________
ERROR: python: commands failed
Run Code Online (Sandbox Code Playgroud)
而不是这样的:
____________________summary _________________
ERROR: test: commands failed
ERROR: lint: commands failed
ERROR: mypy: commands failed
test: commands succeeded
Run Code Online (Sandbox Code Playgroud)
Cry*_*ops 10
使用生成名称和特定于因素的命令(在 tox 配置文档页面中搜索这些术语以获取更多信息)将所有所需的环境实现为一个,以便它们共享相同的 envdir:
[testenv:{lint,flake8,mypy,test}]
envdir = {toxworkdir}/.work_env
deps = pylint, flake8, pytest
commands =
lint: pylint .
flake8: flake8 .
mypy: mypy . --strict
test: pytest
Run Code Online (Sandbox Code Playgroud)
在 tox 4+ 中,您可以使用插件tox-ignore-env-name-mismatch并runner = ignore_env_name_mismatch在 testenv 中进行设置,以允许不同名称的 testenv 共享相同的 virtualenv。