簡體   English   中英

如何獲得 tox 以測試具有不同 python 版本的“命名”測試環境?

[英]How to get tox to test "named" test environments with different python versions?

例如,假設我在 tox.ini 中有關注

[tox]
envlist = py27, py35, testenv2

[testenv]  
 # settings related to "default" testenv - includes deps, commands

[testenv:testenv2]  
 # settings related to testenv2 - includes deps, commands

現在,當我運行 tox 命令時,它使用 python 2.7 和 3.5 解釋器調用testenv命令,但testenv2命令僅在機器上安裝了基本 python 的情況下調用(在我的情況下為 2.7)。 如何讓 tox 也測試像testenv2這樣的“命名”(非默認)測試環境,以使用多個 python 版本進行測試?

第一個答案描述了兩種可行的方法。 為了完整性:您還可以生成環境並使用條件設置 - 例如:

[tox]
skipsdist = True
envlist = py{27,35}-{test,lint}
[testenv]
skip_install = True
deps =
    test: pytest
    test: pytest-xprocess
    lint: flake8
    lint: black
commands =
    test: pytest -v
    lint: flake8
    lint: black .

會生成( tox -a ):

py27-test
py27-lint
py35-test
py35-lint

您可以使用任何因素(例如 py27 或 test)有條件地添加命令、deps 等。

另請參閱文檔

順便說一句:要查看每個 testenv 究竟有哪些設置,您可以運行tox --showconfig

明確列出所有環境:

[tox]
envlist = py27, py35, py27-testenv2, py35-testenv2

如果這還不夠重構tox.ini

[testenv]  
 # settings related to "default" testenv - includes deps, commands

[testenv2]  
 # settings related to testenv2 - includes deps, commands

[testenv:py27-testenv2]  
deps = {[testenv2]deps}
commands = {[testenv2]commands}

[testenv:py35-testenv2]  
deps = {[testenv2]deps}
commands = {[testenv2]commands}

我可以通過制作多個“命名”測試環境來使用多個basepython版本測試“命名”測試環境,每個環境用於不同的 python 版本要測試的測試環境。 以下是有效的示例:

[tox]
envlist = py27, py35, testenv2_py27, testenv2_py35

[testenv]  
 # settings related to "default" testenv - includes deps, commands

[testenv:testenv2_py27]
basepython = python2.7 
 # settings related to testenv2 - includes deps, commands

[testenv:testenv2_py35]
basepython = python3.5  
 # settings related to testenv2 - includes deps, commands

以防萬一有人仍然需要這個,我想出了一個更簡潔的解決方案。 它結合了其他答案的所有好的建議:

[tox]
envlist = py{27,35}, testenv2-py{27,35}

[testenv]  
 # settings related to "default" testenv - includes deps, commands

[testenv:testenv2-py{27,35}]
 # settings related to testenv2 - includes deps, commands

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM