Pytest标记用例失败之xfail

20 篇文章 25 订阅

       项目自动化测试中,如果接口2依赖接口1的响应结果值,或者用例2依赖用例1的响应结果值,自然需要与接口1或用例1进行关联,但是当接口1或用例1执行失败,接口2或用例2一定也是失败的,所以这时不必要再进行接口2和用例2的执行,只需要判断当接口1或用例1执行失败,直接标记接口2或用例2失败xfail

1、pytest 里面用 xfail 标记用例为失败的用例 pytest.xfail('跳过test_two用例标记为失败')
2、标记xfail失败的标识是

x                                                              [100%]

============================= 1 xfailed in 0.18s ==============================

import pytest,sys
class Test(object):
    @pytest.fixture()
    def login(self):
        login_respones=False
        if login_respones:
            return True
        else:
            return False
    def test_two(self,login):
        print('login响应结果是%s:'%login)
        if login==False:
            pytest.xfail('跳过test_two用例标记为失败')
if __name__=='__main__':
    pytest.main(['-s','test01.py'])


"C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/Test/test/test01.py
============================= test session starts =============================
platform win32 -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0
rootdir: C:\Users\wangli\PycharmProjects\Test\test
plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0
collected 1 item

test01.py login响应结果是False:
x

============================= 1 xfailed in 0.18s ==============================

Process finished with exit code 0


 


 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王大力测试进阶之路

打赏博主喝瓶水吧!!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值