• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

博客园    首页    新随笔    联系   管理    订阅  订阅
测试框架--pytest统计case运行结果

统计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))

 

 

posted on 2021-08-06 16:41  搁浅小夕  阅读(792)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3