例如,如果你有:
@pytest.mark.parametrize('lang',
["EN",
"FR"])
def test_whats_hot_quick_links_are_displayed(self, lang):
# Do something here
我有这个拆解夹具:
@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)
那么,如果在执行EN和FR测试运行后执行拆卸功能,而不是在每个参数运行后运行,我怎样才能执行拆解功能?
答案 0 :(得分:1)
对于此行为,我使用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