Pytest-命令行参数--durations的使用
--durations用于计算每个用例执行的执行时间,并进行排序
> pytest -h --durations=N show N slowest setup/test durations (N=0 for all). --durations-min=N Minimal duration in seconds for inclusion in slowest list. Default 0.005
--durations=0时,显示所有用例的执行时间
========================================================================= slowest durations ========================================================================= 0.50s call testcases/login_demo/test_users_login.py::TestUsersLogin::test_users_login 0.26s call testcases/login_demo/test_users_login.py::TestUsersLogin::test_v3_login 0.22s setup testcases/goods_demo/test_v1_goods.py::TestGoods::test_v1_goods[goods_data0] 0.22s call testcases/login_demo/test_v1_register.py::TestUserRegister::test_v1_register 0.21s call testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login 0.21s teardown testcases/login_demo/test_v1_register.py::TestUserRegister::test_v1_register 0.21s call testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login_pwd 0.18s call testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login_username 0.17s call testcases/goods_demo/test_v1_goods.py::TestGoods::test_v1_goods[goods_data0] 0.10s call testcases/goods_demo/test_v1_goods.py::TestGoods::test_v1_goods[goods_data1]
--durations=5时,显示执行时间最慢的5条用例
======================================================================== slowest 5 durations ======================================================================== 0.51s call testcases/login_demo/test_users_login.py::TestUsersLogin::test_users_login 0.27s call testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login 0.21s call testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login_username 0.21s teardown testcases/login_demo/test_v1_register.py::TestUserRegister::test_v1_register 0.20s call testcases/login_demo/test_v1_register.py::TestUserRegister::test_v1_register
注:
call-测试用例
setup-前置
teardown-后置
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具