【问题标题】:How to aggregate test results to publish to testrail after executing pytest tests with xdist?使用 xdist 执行 pytest 测试后,如何汇总测试结果以发布到 testrail?
【发布时间】:2019-11-27 13:38:48
【问题描述】:

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

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

我希望只创建一个测试运行,但仍会创建多个测试运行。

【问题讨论】:

标签: pytest testrail xdist


【解决方案1】:

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

【讨论】:

  • 谢谢@Sergei。我找到了通过解析 xml 的测试结果和 conftest.py 的帮助来做到这一点的方法
猜你喜欢
  • 1970-01-01
  • 2019-02-09
  • 1970-01-01
  • 2022-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多