是否可以将参数传递给python中的拆卸夹具?

时间:2016-02-10 16:25:05

标签: python pytest finalizer fixture teardown

我有一堆测试方法需要运行,然后在每次测试后我想在其他地方更新我的结果。 这就是我所拥有的:

@pytest.mark.testcasename('1234')
@pytest.mark.parametrize('lang',
                         ["EN", "FR"])
def test_text(self, request, base_url, lang):
    testrail_conn = TestrailHelper()
    test_case_id = request.node.get_marker("testcasename").args[0]
    base_url = base_url.replace("testEN", "testFR") if lang == "FR" else base_url
    self.navigate(base_url)
    self.wait_for_page_loaded()
    results = self.check_text(lang)
    try:
        assert results
        testrail_conn.update_test_status(test_case_id, test_result=1)
    except AssertionError:
        testrail_conn.update_test_status(test_case_id, test_result=5)

我的问题是我希望update_test_status处于拆卸夹具中,我可以将test_result传递给它。这样我就不需要为每个测试方法编写相同的代码。 有什么想法吗?

由于

1 个答案:

答案 0 :(得分:0)

您可以在request对象上存储内容,例如在request.node上 - 请参阅the docs。或者,您可以使用测试中的fixture(作为参数),并在那里存储 - 或使夹具返回/产生某种数据结构来存储内容。

相关问题