Pytest标记用例失败之xfail

  • 2019 年 12 月 15 日
  • 笔记

项目自动化测试中,如果接口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 FilesPython35python.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:UserswangliPycharmProjectsTesttest  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