pytest接口自动化框架

pytest官方介绍

百度网盘链接:https://pan.baidu.com/s/1SvNRazeqHSy7sFHRtJz18w?pwd=0709
提取码:0709

 插件:

@pytest.mark.skip(reason='跳过Test类,会跳过类中所有方法')
@pytest.mark.parametrize('val', [5,4,3,2,1])  #一条用例传多个参数
    def test_collision_detect_001(self, val):
        duco_cobot.collision_detect(val)
        logger.info("设置碰撞检测等级: {}".format(val))    
@pytest.mark.parametrize('val', [i for i in range(1,9)])

传两个参数@pytest.mark.parametrize('参数名1,参数名2',[(参数1_data[0], 参数2_data[0]),(参数1_data[1], 参数2_data[1])]) 进行参数化
@pytest.mark.repeat(N)重复
@pytest.mark.smoke   设置冒烟用例

@allure.title("用例标题")
@allure.description("用例描述")
@allure.step("用例步骤")

 test_case

 1 import pytest
 2 import allure
 3 
 4 @allure.title("用例标题")
 5 class Test_Linux2671():
 6 
 7     @allure.description("""
 8     用例描述
 9     比如前置信息
10     比如环境信息
11     比如注释等等
12     """)
13     def setup_class(self):
14         duco_recv.open()
15 
16     def setup(self):
17         self.log_start = duco_recv.get_last_error()
18 
19     @allure.step("用例步骤")
20     def test_linux2671_001(self):
21         print("13岁丧母")
22         print("25岁科举二次落榜")
23 print("36岁龙场悟道")
24 25 def teardown_class(self): 26 wym.close() 27 28 if __name__ == '__main__': 29 pytest.main(["-vs"])

 pytest.ini   (pytest.ini 配置文件不支持注释)

1 [pytest]
2 addopts = --alluredir ./tmp --clean-alluredir
3 testpaths=testcases/
4 python_files=test_*.py
5 python_classes=Test*
6 python_functions=test_*
7 timeout=300 

 run_all.py

1 if __name__ == '__main__':
2     pytest.main(["testcases"])
3     os.system("allure generate ./tmp -o ./reports --clean")

report

 

 

物不可穷也,故受之以未济,终焉

posted @ 2022-08-01 11:12  心如__止水  阅读(576)  评论(0编辑  收藏  举报