You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Tox在Windows与Linux系统下执行不同的pytest命令?

解决tox默认环境不执行测试的问题

你的问题根源在于commands配置项仅定义了带linux:和win32:前缀的环境专属命令,tox默认环境(直接执行tox时触发的环境)没有匹配的执行指令,因此不会自动运行测试。

可以通过两种方案修复:

方案一:添加默认通用命令

给commands增加不带环境限定的基础命令,让所有环境(包括默认环境)都有执行逻辑,仅针对特定环境做差异化覆盖:

[testenv]
commands =
  py.test {posargs}
  win32: py.test -m "not fails_on_windows" {posargs}

deps =
  pyflakes
  pytest

此配置下,默认环境和linux环境都会执行py.test {posargs},win32环境则会使用带标记过滤的专属命令。

方案二:指定默认运行环境列表

在配置中添加envlist字段,将linux和win32设为默认要执行的环境集合,直接运行tox时会自动遍历这两个环境:

[tox]
envlist = linux, win32

[testenv]
commands =
  linux: py.test {posargs}
  win32: py.test -m "not fails_on_windows" {posargs}

deps =
  pyflakes
  pytest

这种方式下,无需手动指定-e参数,执行tox就会依次运行两个环境的测试。

内容的提问来源于stack exchange,提问作者Spitfire19

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 15:08:18