在一个测试环境中,我想根据我当前运行的平台执行两个命令之一。然而,tox 的文档在这方面有点缺乏。我找到了关于多平台测试的 tutorial,以及关于简单平台条件的 example。基于它们,我可以创建一个运行或不基于平台的环境:
[testenv]
platform = win32
commands = python -c 'import sys; print(sys.platform)'
以及基于平台运行或不运行的一组环境:
[tox]
envlist = py-{linux,mac,win}
[testenv]
platform =
linux: linux
mac: darwin
win: win32
commands =
linux: python -c 'print("Linux")'
mac: python -c 'print("Mac")'
win: python -c 'print("Win")'
但是我失败的地方是创建一个可以用单个名称引用的环境,但仍然可以运行依赖于平台的命令。这一切都成功运行,但没有输出:
[tox]
envlist = whatever,platform-{linux,mac,win}
[testenv:whatever]
commands = python -c 'print("whatever")'
[testenv:platform]
platform =
linux: linux
mac: darwin
win: win32
commands =
linux: python -c 'print("Linux")'
mac: python -c 'print("Mac")'
win: python -c 'print("Win")'
; $ tox
; whatever: success, output "whatever"
; platform-linux: success, no output
; platform-mac: success, no output
; platform-win: success, no output
;
; $ tox -e platform
; platform: success, no output
所有平台选项都“成功”运行,没有输出。运行 tox -e platform
而不是裸 tox
不会产生条件环境和输出。
当平台规范移到父级 testenv
时,它几乎有效!
[tox]
envlist = whatever,platform-{linux,mac,win}
[testenv]
platform =
linux: linux
mac: darwin
win: win32
[testenv:whatever]
commands = python -c 'print("whatever")'
[testenv:platform]
commands =
linux: python -c 'print("Linux")'
mac: python -c 'print("Mac")'
win: python -c 'print("Win")'
; $ tox
; whatever: success, output "whatever"
; platform-linux: skipped
; platform-mac: skipped
; platform-win: success, no output
;
; $ tox -e platform
; platform: success, no output
;
; $ tox -e platform-win
; platform-win: success, no output
但问题是 tox
或 -e platform
或 -e platform-win
再次没有产生任何输出。
那么,我怎么能让一个裸 tox
执行正确的命令并且仍然能够手动运行单个环境?甚至有可能使用 tox 吗?