pytest实现接口自动化平台四

四,pytest跳过测试用例

(1)无条件跳过

@pytest.mark.skip(reason ="无理由跳过")

(2)有条件跳过

@pytest.mark.skipif(age>35,reason ="年龄大于35岁")

五,pytest测试用例前后置,固件

#测试装置简绍
#类型                             规则
setup_module/teardown_module   # 全局模块
setup_class/teardown_module     #类级别,只在类中前后置运行一次
setup_function/teardown_module #函数级别,在类外
setup/teardown                 #在类中运行在调用方法的前后(重点)

用例前后置条件放到一个py文件中common_util.py

class CommonUtil:
    def setup_class(self):
        print('每个类之前执行一次')
    def teardown_class(self):
        print('每个类之后执行一次')
    def setup(self):
        print('每个用例之前执行一次')
    def teardown(self):
        print('每个用例之后执行一次')

六,使用fixtrue实现部分前后置

@pytest.fixture(scope="function", autouse=False, params=read_yaml(),ids=["d","e","f"],name='db')
scope ="function"  #scope 作用域:function 函数级别 , class 类级别 类之前之后,package/session 项目会话级别,项目会话前和会话之后执行
autouse=False True     #autouse 是否自动执行 False 否,True是

@pytest.fixture(scope="function", autouse=True)
def exe_database_sql(request):
    print("执行sql查询")
    yield                  #function执行后执行
    print("关闭数据库链接")

Original: https://blog.csdn.net/xiongjuexing/article/details/126776287
Author: xiongpython
Title: pytest实现接口自动化平台四

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/775386/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球