跳轉至

建立 2026-10-11 更新 2026-10-11

核心技巧

核心技巧是每個 pytest 專案都會用到的四項功能:用 assert 與 pytest.raises 驗證結果、用 fixture 準備測試環境、用參數化讓一個測試跑多組資料、用 marker 為測試分類與控制是否執行。這四項就是 pytest 最值得優先投資的 20%。

頁面 你會學到
assert 與例外測試 比對值、浮點數、例外與警告
Fixture 準備與清理、yield、scope、fixture 互相依賴
參數化測試 @pytest.mark.parametrize、pytest.param、測試 ID
Marker skip、skipif、xfail 與自訂標記