歡迎來到tox自動化項目?
愿景:在Python中標準化測試?
tox
旨在自動化和標準化Python中的測試。它是簡化Python軟件打包、測試和發布過程的更大愿景的一部分。
什么是tox??
tox是一種通用 virtualenv 管理和測試命令行工具,可用于:
檢查軟件包是否使用不同的Python版本和解釋器正確安裝
在每個環境中運行測試,配置您選擇的測試工具
充當持續集成服務器的前端,極大地減少了樣板,并合并了CI和基于shell的測試。
基本實例?
首先,安裝 tox
具有 pip install tox
。然后將有關項目的基本信息以及要在其中運行項目的測試環境放入 tox.ini
文件就駐留在您的 setup.py
文件:
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py27,py36
[testenv]
# install pytest in the virtualenv where commands will be executed
deps = pytest
commands =
# NOTE: you can run any command line tool here - not just tests
pytest
您還可以嘗試生成 tox.ini
自動創建文件,方法是運行 tox-quickstart
然后回答幾個簡單的問題。
要使用Python2.7和Python3.6對項目進行sdist打包、安裝和測試,只需鍵入::
tox
并觀察發生的情況(您的環境中必須安裝python2.7和python3.6,否則您將看到錯誤)。當你跑步的時候 tox
第二次,您會注意到它的運行速度要快得多,因為它跟蹤viralenv細節,并且不會重新創建或重新安裝依賴項。您可能還想結賬 tox配置和使用示例 以獲得更多的想法。
系統概述?

tox 工作流程圖?
tox大致遵循以下階段:
配置: load
tox.ini
并將其與來自命令行的選項和操作系統環境變量合并。打包 (可選):通過調用以下命令創建當前項目的源分發
python setup.py sdist
請注意,對于此操作,將使用與安裝TOX的環境相同的Python環境(因此,您需要確保它包含您的構建依賴項)。對于沒有
setup.py
.環境 -對于每個 tox 環境(例如
py27
,py36
)執行以下操作:1. environment creation: create a fresh environment, by default virtualenv is used. tox will automatically try to discover a valid Python interpreter version by using the environment name (e.g.
py27
means Python 2.7 and thebasepython
configuration value) and the current operating systemPATH
value. This is created at first run only to be re-used at subsequent runs. If certain aspects of the project change, a re-creation of the environment is automatically triggered. To force the recreation tox can be invoked with-r
/--recreate
.2.第二步。 安裝 (可選):安裝在
deps
配置部分,然后是較早打包的源代碼發行版。默認情況下,pip
用于安裝軟件包,但是您可以通過以下方式對其進行自定義install_command
。注意事項pip
不會更新項目依賴項(在install_requires
或extras
剖面圖setup.py
)如果虛擬環境中已存在任何版本;因此,我們建議您在項目依賴關系更改時重新創建您的環境。三。 命令 :按指定順序運行指定的命令。只要它們中的任何一個的退出代碼不是零,就停止,并將環境標記為失敗。注意,命令以單個短劃線字符開頭表示忽略退出代碼。
報告 打印出每個 tox 環境的結果報告:
____________________ summary ____________________ py27: commands succeeded ERROR: py36: commands failed
只有在所有環境都成功運行的情況下,tox才會返回退出代碼
0
(成功)。在這種情況下,您還將看到以下消息congratulations :)
.
TOX將為您提供環境隔離:它將剝離所有未通過以下方式指定的操作系統環境變量 passenv
。此外,它還將改變 PATH
變量,以便您的命令首先在當前活動的TOX環境中解析。通常,路徑中的所有可執行文件都可在 commands
,但如果沒有明確允許通過 allowlist_externals
.
當前功能?
單調乏味的Python相關測試活動的自動化
針對許多解釋器和依賴項配置測試您的Python包
自動自定義(重新)創建 virtualenv 測試環境
安裝您的
setup.py
將基于項目的項目添加到每個虛擬環境中測試工具不可知:以統一的方式運行pytest、nash或unittest
plugin system 用簡單的鉤子修改tox執行。
用途 pip 和 setuptools 默認情況下。支持通過配置安裝程序命令
install_command = ARGV
。cross-Python compatible :CPython-2.7、3.5及更高版本,Jython和 pypy.
cross-platform :Windows和Unix風格的環境
與持續集成服務器集成 喜歡 Jenkins (以前稱為Hudson),并幫助您避免boilerpltis和特定于平臺的構建步驟。
與devpi完全互操作性 :與集成在一起,并用于在 devpi 系統,一個通用的PyPI索引服務器和發布管理工具。
driven by a simple ini-style config file
文件化的 examples 和 configuration
簡明扼要的報道 關于工具調用和配置錯誤
專業的 supported