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 测试入门