是否可以仅在所有参数运行后才运行拆卸装置?

2023-11-29

例如,如果您有:

@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)

那么我怎样才能使拆卸函数仅在执行 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

是否可以仅在所有参数运行后才运行拆卸装置? 的相关文章

随机推荐