''' 接口测试用例 ''' import os import allure import pytest # 进行接口用例的编写 desc = "<font color='red'>请求URL:</font>{}<br/>" \ "<font color='red'>请求类型:</font>{}<br/>" \ "<font color='red'>期望结果:</font>{}<br/>" \ "<font color='red'>实际结果描述:</font>{}<br/>" \ .format("http://www.baidu.com","post","200","404") @allure.description("原始描述") def test_dynamic_desc(): # 断言成功后,可以在测试用例内部动态更新描述 assert 42==int(6*7) # 断言失败不会动态更新描述 # assert 43==int(6*7) allure.dynamic.description(desc) @allure.title('原始标题') def test_with_dynamic_title(): assert 2+2==4 allure.dynamic.title("断言成功,用例标题动态更新") @allure.title("参数化用例标题:添加{param1} 和 {param2}") @pytest.mark.parametrize('param1,param2,expected', [(2,2,4),(2,3,6)]) def test_with_param(param1,param2,expected): assert param1 + param2 == expected if __name__ == '__main__': pytest.main(['-s', 'test_007.py', '--alluredir', './result', '--clean-alluredir']) os.system('copy environment.properties result\\environment.properties') os.system('allure serve result')