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

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

谢谢

最佳答案

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

关于python - 是否可以将参数传递给python中的拆卸 fixture ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35320569/

相关文章:

c# - 为什么结构不能有析构函数?

python - 我怎样才能确保我的类的一个方法总是被调用,即使一个子类覆盖了它?

python - 将自定义标记应用于 pytest 参数化标记的特定值

python - 如何找到 JSON 列表中的哪一项对于 Python 中的给定属性具有最大值?

python - 为什么我的当前目录没有出现在 Windows 上使用 pytest 的路径中?

python - 为什么 pytest 总是说 "ImportError: attempted relative import with no known parent package"

c# - 什么时候不能使用 SafeHandle 而不是 Finalizer/IDisposable?

c# - 为什么 WeakReference.IsAlive 变为假?

Python 统一码 : why in one machine works but in another one it failed sometimes?

python - 以特殊条件连接 pandas 数据框