0
点赞
收藏
分享

微信扫一扫

pytest 前置后置使用方法

在我们某一系列用例运行前,我们需要做一些准备工作。这样的行为势必会产生大量的重复代码.那么在这种情况下,pytest给我们提供了丰富的前置和后置的方法

pytest里包含了 setUp 和 teardown对应的内容

用例运行级别

模块级(setup module/teardown module): 开始于模块的始末,全局的函数级(setup function/teardown function): 只对函数用例生效 (不在类中)

类级(setup class/teardown class): 只在类中前后运行一次方法级(setup method/teardown method): 开始于方法始末(在类中)类里面的(setup/teardowp): 运行在调用方法的前后

通过方法名来确定它的执行逻辑

def setup function():

print("每个用例前都会执行我一次: setup")

def teardown function():

print("每个用例后都会执行我一次: teardwon")

def test one():

print("第一个用例---执行")

str = "huace"

assert "h" in str

0

举报

相关推荐

0 条评论