pytest指定fixture做用範圍

#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

相關文章
相關標籤/搜索