统计case运行的结果需要使用pytest-json-report插件,需要安装
pip install pytest-json-report
1 import pytest 2 from pytest_jsonreport.plugin import JSONReport 3 4 5 6 class TestCase: 7 def test_print(self): 8 print("test_print") 9 10 def test_hello(self): 11 print("test_hello") 12 13 def test_normal(self): # 可以加多个标签 14 print("test_normal") 15 1/0 16 17 18 class TestCase2: # 装饰类的方式 19 20 def test_mygod(self): 21 print("test_mygod!!!") 22 assert 1==2 23 24 def test_my(self): 25 print("test_my!!!!") 26 27 28 class TestCase3: 29 def test_car(self): 30 print("test_car!!!") 31 32 @pytest.mark.skip("!!") 33 def test_car1(self): 34 print("test_car!!!") 35 36 def fly(self): 37 print("test_fly!!!!") 38 39 40 41 def test_user(): # 可以加多个标签 42 print("test_user") 43 44 45 if __name__ == '__main__': 46 plugin = JSONReport() 47 pytest.main(['--json-report-file=none', __file__], plugins=[plugin]) 48 summary = plugin.report.get("summary") 49 passed = summary.get("passed",0) 50 failed = summary.get("failed",0) 51 skipped = summary.get("skipped",0) 52 total = summary.get("total",0) 53 print("共{}条,通过{}条,失败{}条,跳过{}条".format(total,passed,failed,skipped))
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?