#scope参数有四个待选值:function(默认)、class、module、session。

@pytest.fixture(scope='function')
def function_scope():
    return "function_scope"

@pytest.fixture(scope='class')
def class_scope():
    return "class_scope"

@pytest.fixture(scope='module')
def module_scope():
    return "module_scope"

@pytest.fixture(scope='session')
def session_scope():
    return "session_scope"

@pytest.mark.usefixtures("class_scope")
class Testscope():

    def test_1(self,session_scope,module_scope,function_scope):
        assert True

    def test_2(self,session_scope,module_scope,function_scope):
        assert True
 
pytest --setup-show test_demo.py

pytest指定fixture作用范围

 

 
 

相关文章:

  • 2021-12-20
  • 2022-12-23
  • 2021-07-20
  • 2021-12-27
  • 2022-12-23
  • 2021-04-28
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2022-03-08
  • 2022-12-23
  • 2021-10-21
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
相关资源
相似解决方案