2.5 KiB
2.5 KiB
author | date | category | tags | ||||
---|---|---|---|---|---|---|---|
deng | 20250122 | Note |
|
- Abstract
- Resources
- 心法
- 為什麼你應該寫單元測試——《Python 工匠》筆記 - Code and Me
- 入門
- Python 測試入門 - 開始使用 PyTest - 拾遺
- # Python 測試入門 - PyTest Fixture - 拾遺
- 7 個實用的 pytest plugins - MyApollo
- Pytest 101 - 給 Python 開發者的測試入門 (3) - 圖解 Mock & 測試框架語法整理 - Byte and Ink
- How To Test Python Exception Handling Using Pytest Assert (A Simple Guide) - Pytest with Eric
- 更上一層樓
- 13 Proven Ways To Improve Test Runtime With Pytest - Pytest with Eric
- 對於進階者相當推薦Eric的部落格,有相當多的情境可以參考
- 13 Proven Ways To Improve Test Runtime With Pytest - Pytest with Eric
- 心法
- Note
- 雖不追求100%測試覆蓋率,但我在寫測試時都會裝上Pytest-cov插件以掌握專案當下覆蓋率的情況
- 透過
--cov
引數調用,例如pytest --cov=./src ./tests
- 透過
- 專案越肥大通常測試會花上更多時間,搭配Pytest-xdist插件可簡單地將測試平行化以節省寶貴時間
- 透過
-n
引數調用,例如pytest -n auto
- 若測試物件之間有依賴性,可使用xdist_group_mark將物件分群,同群的物件將會在同一行程內執行
- 平行化通常伴隨更多資源的消耗,使用時需小心~
- 透過
- 善用Fixture將某些資料暫存給後續測試使用,進一步節省測試時間
- Pytest也支援pyproject.toml進行配置哦
- 雖不追求100%測試覆蓋率,但我在寫測試時都會裝上Pytest-cov插件以掌握專案當下覆蓋率的情況