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