例如,如果您有:
@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测试运行之后才执行,而不是在每个参数运行之后都运行该拆卸功能?
解决方法:
对于这种行为,我使用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