pytest:協助您編寫更好的程式¶
pytest
框架使編寫小型、可讀的測試變得容易,並且可以擴展以支援應用程式和函式庫的複雜功能測試。
pytest
需要:Python 3.8+ 或 PyPy3。
PyPI 套件名稱:pytest
快速範例¶
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
執行它
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-8.x.y, pluggy-1.x.y
rootdir: /home/sweet/project
collected 1 item
test_sample.py F [100%]
================================= FAILURES =================================
_______________________________ test_answer ________________________________
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)
test_sample.py:6: AssertionError
========================= short test summary info ==========================
FAILED test_sample.py::test_answer - assert 4 == 5
============================ 1 failed in 0.12s =============================
由於 pytest
詳細的斷言內省,僅使用簡單的 assert
陳述式。請參閱 開始使用 以獲得使用 pytest 的基本介紹。
功能¶
關於失敗的 assert 陳述式 的詳細資訊 (無需記住
self.assert*
名稱)自動探索 測試模組和函數
模組化 fixtures 用於管理小型或參數化的長期測試資源
可以開箱即用地執行 unittest (包括 trial) 測試套件
Python 3.8+ 或 PyPy 3
豐富的插件架構,擁有超過 1300 個 外部插件 和蓬勃發展的社群
文件¶
錯誤/請求¶
請使用 GitHub issue tracker 提交錯誤或請求功能。
支持 pytest¶
Open Collective 是一個用於開放和透明社群的線上募款平台。它提供工具來籌集資金並以完全透明的方式分享您的財務狀況。
它是希望直接向專案進行一次性或每月捐款的個人和公司的首選平台。
請在 pytest collective 中查看更多詳細資訊。
企業版 pytest¶
作為 Tidelift 訂閱的一部分提供。
pytest 和數千個其他套件的維護者正在與 Tidelift 合作,為您用於構建應用程式的開源依賴項提供商業支援和維護。節省時間、降低風險並改善程式碼健康狀況,同時向您使用的確切依賴項的維護者付費。
安全性¶
pytest 從未與安全漏洞相關聯,但在任何情況下,要報告安全漏洞,請使用 Tidelift 安全聯絡方式。Tidelift 將協調修復和披露。