目录
前言
代码示例
前言
- 自动化测试中,有关联依赖关系的用例,当前置的用例失败时,后面的用例可以标记xfail,直接跳过不再执行。
代码示例
# -*- coding: utf-8 -*-
# @Time : 2021/10/23
# @Author : 大海
# @File : test_27.py
import pytest
params = [{"username": "大海", "password": "12345"}]
@pytest.fixture()
def login(request):
user = request.param["username"]
pwd = request.param["password"]
print("正在操作登录,账号:%s, 密码:%s" % (user, pwd))
if pwd == "123456":
return True
else:
return False
# case1 测试登录 结果为fail,case2和3 先判断登录结果,登录失败 直接标记xfail 不执行
@pytest.mark.parametrize("login", params,indirect=True)
class TestShopping():
def test1_login(self, login):
"""用例1 测试登录"""
result = login
print("用例1:%s" % result)
assert result == True
def test2_add_shopping_car(self,login):
"""用例2 添加购物车"""
result = login
print("用例3,登录结果:%s" % result)
if not result:
pytest.xfail("登录不成功, 标记为xfail")
assert 1 == 1
def test3_pay(self, login):
"""用例3 支付"""
result = login
print("用例3,登录结果:%s" % result)
if not result:
pytest.xfail("登录不成功, 标记为xfail")
assert 1 == 1
if __name__ == "__main__":
pytest.main(["-s", "test_27.py"])
|