Python 測試入門
Alexander Levin
Data Scientist
效能(Performance):軟體為完成任務時,對系統資源的使用效率。
效能測試(Performance Testing):量測軟體效能的一種測試。
資源:
情境:
安裝:
pip install pytest-benchmark
# Example_1.py
import time
def test_func(benchmark):
benchmark(time.sleep, 1)
CLI 指令:
pytest Example_1.py
執行上述 CLI 指令後的結果:

將 time.sleep(1) 改為 time.sleep(3):

# Example_2.py
import time
def test_func(benchmark):
@benchmark
def sleep_for_1_sec():
time.sleep(1)
CLI 指令:
pytest Example_2.py
pytest-benchmark 的方式:benchmark@benchmark 作為裝飾器Python 測試入門