pytest学习实践-day3-测试函数执行顺序-class 内部

# zhouchong
# 模块和方法级 实践

import pytest


class TestCase(object):

    def setup_class(self):
        print("\nsetup_class: 所有用例执行之前")

    def teardown_class(self):
        print("\nteardown_class: 所有用例执行之后 ")

    def setup_method(self):
        print("\nsetup_method: 每个用例执行之前执行")

    def teardown_method(self):
        print("\nteardown_method: 每个用例执行结束后执行 ")

    # def setup(self):
    #     print("\nsetup: 每个用例开始前都会执行222")
    #
    # def teardown(self):
    #     print("\nsetup: 每个用例结束后都会执行222")

    def test_three(self):
        print("正在执行测试类 ---- test_three")

    def test_four(self):
        print("正在执行测试类 ---- test_four")


if __name__ == "main":
    pytest.main(["-s", "XXXX"])

执行结果:

============================= test session starts =============================
collecting ... collected 2 items

test_02_pytest执行顺序基础_2.py::TestCase::test_three <- ..\c1\test_02_pytest执行顺序基础_2.py 
setup_class: 所有用例执行之前

setup_method: 每个用例执行之前执行
PASSED [ 50%]正在执行测试类 ---- test_three

teardown_method: 每个用例执行结束后执行 

test_02_pytest执行顺序基础_2.py::TestCase::test_four <- ..\c1\test_02_pytest执行顺序基础_2.py 
setup_method: 每个用例执行之前执行
PASSED [100%]正在执行测试类 ---- test_four

teardown_method: 每个用例执行结束后执行 

teardown_class: 所有用例执行之后 


============================== 2 passed in 0.02s ==============================

结论:

# 执行顺序
# setup_class> (setup_method>case>teardown_method)*N > teardown_class
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值