zoukankan      html  css  js  c++  java
  • pytest扫盲16--某个用例失败后,关联的用例标记为xfail

    设计思路:设计用例时,如果用例执行失败,则标记 xfail,所有引用该用例的其他用例,均调用该 xfail 标记

    示例:

    # File  : test_demo_16.py
    # IDE   : PyCharm
    
    import pytest
    
    @pytest.fixture(params=[{'user': 'admin', 'pwd': '1234'}])
    def login(request):
        '''前置条件登录'''
        print("
    正在操作登录,账号:%s, 密码:%s" % (request.param['user'], request.param['pwd']))
        if request.param['pwd'] == '123456':
            print('登录成功')
            return True
        else:
            print('登录失败')
            pytest.xfail(reason='登录失败,标记为xfail')
            return False
    
    class TestLogin:
        def test_1(self, login):
            assert 5 > 6
    
        def test_2(self, login):
            assert 'h' in 'hello'
    
        def test_3(self):
            assert 3 is 3

    当前置条件执行失败时,执行结果:

    E:personalpython38python.exe E:/personal/GitWorkSpace/pytest_basic/main.py
    test_demo_16.py::TestLogin::test_1[login0]
    test_demo_16.py::TestLogin::test_2[login0]
    test_demo_16.py::TestLogin::test_3
    
    正在操作登录,账号:admin, 密码:1234
    登录失败
    x
    正在操作登录,账号:admin, 密码:1234
    登录失败
    x.
    1 passed, 2 xfailed in 0.11s
    
    Process finished with exit code 0

    当前置条件执行成功时,执行结果:

    E:personalpython38python.exe E:/personal/GitWorkSpace/pytest_basic/main.py
    test_demo_16.py::TestLogin::test_1[login0]
    test_demo_16.py::TestLogin::test_2[login0]
    test_demo_16.py::TestLogin::test_3
    
    正在操作登录,账号:admin, 密码:123456
    登录成功
    F
    正在操作登录,账号:admin, 密码:123456
    登录成功
    ..
    ================================== FAILURES ===================================
    __________________________ TestLogin.test_1[login0] ___________________________
    
    self = <pytest_basic.test_demo_16.TestLogin object at 0x000000B010FF80A0>
    login = True
    
        def test_1(self, login):
    >       assert 5 > 6
    E       assert 5 > 6
    
    test_demo_16.py:24: AssertionError
    =========================== short test summary info ===========================
    FAILED test_demo_16.py::TestLogin::test_1[login0] - assert 5 > 6
    1 failed, 2 passed in 0.13s
    
    Process finished with exit code 0
  • 相关阅读:
    修改 cmd 控制台字体、巧用 FontLink 使中英文独立设置
    非常棒的 「Sublime Text 配色/主题」与「编程字体」
    如何优雅地制作精排 ePub —— 个人电子书制作规范及基本样式表
    Simofox 2.7
    轻松绕过极域电子教室、和教师控制 Say GoodBye
    linux常用的命令
    Java Map按键(Key)排序和按值(Value)排序
    关于递归的理解以及实例
    如何去掉list里重复的数据
    快速排序的白话理解(拷贝)
  • 原文地址:https://www.cnblogs.com/xiaohuboke/p/13541894.html
Copyright © 2011-2022 走看看