在自动化测试中,基本都需要使用到pytest框架来管理我们的用例,使用allure框架来生成报告。今天就和大家分享一下这方面的知识,跟着步骤走起来~~~

pytest框架
1、pytest命名规范
pytest测试文件必须以test_开头,或以 _test结尾
测试类必须以Test开头,并且类中不能有init方法
测试方法必须以test开头
断言必须使用assert
2、数据驱动
@pytest.mark.parametrize装饰器可以让测试数据参数化,实现数据驱动,方便代码和测试数据分离
3、多重断言
python
pip install pytest-assume

4、生成allure报告
python
pip install allure-pytest
allure.zip包解压到某个盘符下即可,并配置环境变量
在cmd命令窗口敲

生成allure报告的命令

5、allure的层级
@allure.epic()第一层 表示项目或应用的范围
@allure.feature()第二层 表示功能或模块
@allure.story()第三层 表示测试主题
@allure.title()第四层 表示具体的测试步骤
6、用例步骤

7、用例的严重等级
severity()

以上就是pytest框架+allure报告具体操作步骤,看完文章就跟着练起来吧!
