前言:1、当 pytest.fixture(scope="module") 时,pytest的yieId 类似unittest的teartownclass

   2、当 pytest.fixture(scope="function") 时,pytest的yieId 类似unittest的teartown

          3、其中一个用例出现异常,不会影响yield后面的teardown执行,运行结果互不影响

          4、如果在setup就异常了,那么是不会去执行yield后面的teardown内容了

 

# coding=utf-8
import pytest

@pytest.fixture(scope="module")
def login():
    print("登录成功")

    yield
    print("用例执行完成,收尾")


def test1(login):
    print('操作1')
    print("-----------------------------------------------")

def test12(login):
    print('操作2')
    print("-----------------------------------------------")


def test3(login):
    print('操作3')

    print("-----------------------------------------------")


if __name__ == '__main__':
    pytest.main(['-s', "text.fix2.py"])

运行结果:

pytest 的 yield

# coding=utf-8
import pytest

@pytest.fixture(scope="function")
def login():
    print("登录成功")

    yield
    print("用例执行完成,收尾")


def test1(login):
    print('操作1')
    print("-----------------------------------------------")

def test12(login):
    print('操作2')
    print("-----------------------------------------------")


def test3(login):
    print('操作3')

    print("-----------------------------------------------")


if __name__ == '__main__':
    pytest.main(['-s', "text.fix2.py"])

运行结果:

pytest 的 yield

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2021-12-14
  • 2021-07-22
猜你喜欢
  • 2021-11-20
  • 2022-02-20
  • 2022-02-16
  • 2021-10-29
  • 2022-12-23
  • 2022-01-15
相关资源
相似解决方案