gpt4 book ai didi

pytest - 使用 xdist 执行 pytest 测试后,如何聚合测试结果以发布到 testrail?

转载 作者:行者123 更新时间:2023-12-04 16:45:31 29 4
gpt4 key购买 nike

我遇到了这样的问题。我目前正在使用 pytest 运行测试用例,并使用 xdist 减少执行时间以并行运行测试并将测试结果发布到 TestRail。问题是在使用 xdist 时,pytest-testrail 插件会为每个 xdist worker 创建 Test-Run,然后发布像 Untested 这样的测试用例。

我尝试了这个钩子(Hook) pytest_terminal_summary 来防止 pytest_sessionfinish 插件钩子(Hook)被多次调用。

我预计只创建了一个测试运行,但仍然创建了多个测试运行。

最佳答案

我遇到了同样的问题,但找到了一种使用胶带的解决方法。我发现如果我们使用 --tr-run-id 键运行测试,所有结果都在测试运行中正确收集。如果您使用 jenkins 作业来自动化流程,您可以执行以下操作:1) 使用 testrail API 创建测试运行2) 获取本次测试运行的ID3) 使用 --tr-run-id=$TEST_RUN_ID 运行测试

我使用了这些文档: http://docs.gurock.com/testrail-api2/bindings-python http://docs.gurock.com/testrail-api2/reference-runs

from testrail import *
import sys

client = APIClient('URL')
client.user = 'login'
client.password = 'password'

result = client.send_post('add_run/1', {"name": sys.argv[1], "assignedto_id": 1}).get("id")
print(result)

然后在 jenkins shell 中

RUN_ID=`python3 testrail_run.py $BUILD_TAG`

然后

python3 -m pytest -n 3 --testrail --tr-run-id=$RUN_ID --tr-config=testrail.cfg ...

关于pytest - 使用 xdist 执行 pytest 测试后,如何聚合测试结果以发布到 testrail?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57097553/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com