pytest心得体会

一、如何单独运行某条用例

在参数化测试中总有些用例失败,由于前后置数据的关系需要单独运行那条用例如何运行呢

  • 方法一:直接查看控制台运行用例 确定是[2-case_data8]
python 复制代码
pytest.main(["-sv",
             "testcase/违规告警/test_违规告警_非合同车.py::TestIllegalAlarmNonContract::test_illegal_alarm_non_contract_009[2-case_data8]"])
  • 方法二 查看allure报告 Parameters
    根据 Parameters进行拼接 2-case_data4
    注意 不要使用allure.dynamic.title(case_data["title"])或者 @allure.title()

二、参数化需要可迭代对象

参数化有点像for i in case_data其中i为实际的用例参数

这就是yaml对象中为何会写step01:让其转dict时变为一个列表

三、多个参数化使用时注意参数形式

python 复制代码
@pytest.mark.parametrize("case_data", pd.get_yaml_single_case_data(filename9, api_name))  # [{},{},]
@pytest.mark.parametrize("alarm_type", [2])

同一测试函数存在case_data,alarm_type两个参数化,他们之间是存在组合关系的,组合方式就是笛卡尔积,我想要保证alarm_type每次传2,3两个参数,参数需要写为[(2,3)]

python 复制代码
@pytest.mark.parametrize("alarm_type", [(2,3)])

这就是参数化有点像for i in case_data具体应用,保证i是我们想要的数据,若写成@pytest.mark.parametrize("alarm_type", [2,3])

形成的参数化将为[2-case_data],[3-case_data] 分别进行组合

相关推荐
把头塞进显示器3 天前
电商平台-测试报告
python·selenium·pytest
昔我往昔7 天前
pytest日志问题排查记录
python·pytest
黄昏恋慕黎明10 天前
博客论坛技术迭代
python·pytest
2601_9620782311 天前
Python接口自动化流程(pytest)
python·pytest·接口自动化·测试框架·断言
杨女士YRJ11 天前
python+pytest+01
python·pytest
2601_9620782312 天前
Python接口自动化框架:pytest
python·pytest·接口自动化·测试框架·restfulapi
2601_9620781912 天前
Appium+Python+pytest自动化测试框架详解
自动化测试·python·appium·pytest·移动应用
2601_9622845013 天前
安卓APP UI自动化测试:Python + UiAutomator2 + pytest + pytest-html
python·pytest·uiautomator2·ui自动化测试·安卓app
2601_9623008114 天前
基于pytest的接口自动化测试:使用requests模块的实战项目与接口关联方法详解
接口自动化测试·测试用例·pytest·接口关联·requests模块
2601_9623008114 天前
Python + Requests + Pytest + Excel + Allure:接口自动化测试项目实战
python·excel·pytest·allure·requests