pytest跳过依赖的用例

使用场景:

1.如果我们两个用例有依赖,为了知道依赖的用例是否通过了,如果通过就执行当前用例,没通过就跳过当前用例;

# 在common.py添加一个State类
class
State(object): skip = False
# test_01.py
# 导入这个你设置的State类
from common_class.common(你的类包路径) import State
def test_01():
    try:
        assert 0
    except Exception as e:
        setattr(State, "skip", True)
        raise e

def test_02():
    f = getattr(State, "skip")
    if f is True:
        log.info("依赖用例不通过,跳过该用例")
        pytest.skip()
    else:
        log.info("用例通过")

 

posted @ 2021-10-15 13:30  清风吹拂啊狂风肆虐  阅读(53)  评论(0编辑  收藏  举报