生成了Allure报告,可以自定义一些属性,使报告看起来层级更明显,看起来更清晰。下图显示有些优化的选项
创建测试用例:
import allure # import logging # logging.basicConfig(level=logging.INFO) @allure.epic("测试版本:V1.1") @allure.feature("首页模块") @allure.title("这是首页的测试用例-01") def test01(): print("这是测试用例-01的输出内容") # logging.info("这是测试用例-01 -- log日志") @allure.epic("测试版本:V1.1") @allure.feature("首页模块") @allure.title("这是首页的测试用例-05") def test05(): print("5") @allure.epic("测试版本:V1.2") @allure.title("这是测试用例-02") def test02(): print("2") @allure.epic("测试版本:V1.1") @allure.feature("书籍模块") @allure.title("这是书籍的测试用例-03") def test03(): print("3") @allure.epic("测试版本:V1.1") @allure.feature("登录注册模块") def test04(): print("4")
创建main文件,
import os import pytest def run(): # pytest.main(['--allure-epics=测试版本:V1.1', '--alluredir', './result', '--clean-alluredir']) pytest.main(['--alluredir', './result', '--clean-alluredir']) os.system('allure generate ./result/ -o ./report/ --clean') if __name__ == '__main__': run()
进行执行,查看报告