Python 只有在所有参数运行后才能运行拆卸夹具吗?
例如,如果您有:Python 只有在所有参数运行后才能运行拆卸夹具吗?,python,pytest,finalizer,fixture,teardown,Python,Pytest,Finalizer,Fixture,Teardown,例如,如果您有: @pytest.mark.parametrize('lang', ["EN", "FR"]) def test_whats_hot_quick_links_are_displayed(self, lang): # Do something here 我在conftest中有一个拆卸夹具: @pytest.fixture(scope='function', aut
@pytest.mark.parametrize('lang',
["EN",
"FR"])
def test_whats_hot_quick_links_are_displayed(self, lang):
# Do something here
我在conftest中有一个拆卸夹具:
@pytest.fixture(scope='function', autouse=True)
def teardown_function(request):
def execute_at_the_end():
logging.info("Ending Test Case...")
database.clear()
request.addfinalizer(execute_at_the_end)
那么,我如何才能使teardown函数仅在EN和FR测试运行后执行,而不是在每个参数运行后运行?对于这种行为,我使用
scope=class
并用class
包装我的测试:
import pytest
@pytest.yield_fixture(scope='class')
def teardown_after_all_params():
yield
execute_at_the_end()
@pytest.mark.usefixtures('teardown_after_all_params')
class TestLinks:
@pytest.mark.parametrize('lang', ["EN", "FR"])
def test_whats_hot_quick_links_are_displayed(self, lang):
# Do something here
谢谢非常感谢