2

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

@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 传递给它。这样我就不需要为每种测试方法编写相同的代码..有什么想法吗?

谢谢

4

1 回答 1

0

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

于 2016-02-11T05:46:36.047 回答