微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

可能只有在所有参数运行后才能运行拆卸夹具吗?

例如,如果您有:

@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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐