为什么bamboo junit解析器渲染“未命名测试套件”?
I'm seeing several test cases showing up in a bamboo JUnit Parser step with no test suite name being rendered for the test cases. What can explain this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过模拟测试结果,我们可以看到,bamboo 至少有两种形式的测试套件命名检测。
显式命名的测试套件
最明智的解析操作发生在显式命名的测试套件下。在 xml 中,这通过
testsuite
标记中的name
属性显示。在这种情况下,bamboo 可以正确解析测试套件的名称,如下所示:

Pytest 生成 xml
Pytest 在生成 junit xml 时,通过 --junit-xml=xml_path.xml 参数,有一个约定,即使用通用名称注入测试套件名称
pytest
字符串留在 默认值junit_suite_name
。Bamboo 似乎熟悉这种约定,并且实际上会回退到解析测试用例的类名属性,以在
.
字符上进行标记,以提取后面的子字符串。请注意上述 xml 的以下输出:我们可以看到,对于具有空 classname 属性的测试用例,Bamboo 可以稳健地处理这种情况,但最终无法确定测试套件名称并失败后退到
未命名测试套件
表示,因为这就是此类测试用例的所有上下文。背景故事:事实证明,从 bazel 执行运行 pytest junit 生成会以某种方式剥离或干扰类名生成。目前还不完全清楚为什么我会出现这种情况。 pytest 在以下源中生成此属性的值 https://github.com/pytest-dev/pytest/blob/55debfad1f690d11da3b33022d55c49060460e44/src/_pytest/junitxml.py#L126。我也许可以追踪代码库,看看是否可以确定任何内容。
背景故事更新 2022 年 3 月 21 日
我最终深入研究了 bazel 行为并编写了
nodes.py
的仪表化构建,本质上发现会话根目录无法通过其相对路径逻辑的实现session.config.rootdir 建立
。看https://github.com/pytest-dev/pytest/discussions/9807 了解详情。
Playing around with a dummy test result we can see that bamboo has at least two forms of test suite naming detection.
Explicitly named Testsuite
The most sensible parsing operation happens under an explicitly named test suite. In the xml this shows by the
name
attribute in thetestsuite
tag.In this circumstance bamboo properly parses the testsuite's name as seen here:

Pytest generated xml
Pytest when it generates junit xml, via the --junit-xml=xml_path.xml argument, has a convention of injecting the testsuite name with the generic
pytest
string when left to the default value for itsjunit_suite_name
.Bamboo appears to be familiar with this convention and will actually fallback to parsing the classname attribute for the testcases to tokenize on the
.
character to extract the substring which follows. Note the following output from the above xml:We can see that for the test cases with an empty classname attribute Bamboo robustly handles that case but ultimately cannot determine the test suite name and falls back to the
unnamed test suite
representation since that's all the context it has for such test cases.backstory: it turns out that running pytest junit generation from a bazel execution somehow strips or interferes with the classname generation. It's not entirely clear why this is the case to me at this point in time. pytest generates the value for this attribute in the following source https://github.com/pytest-dev/pytest/blob/55debfad1f690d11da3b33022d55c49060460e44/src/_pytest/junitxml.py#L126. I may be able to trace up through the codebase to see if anything can be determined there.
Backstory update 3/21/2022
I wound up digging into the bazel behavior and authoring an instrumented build of
nodes.py
and essentially found the session root dir could not be established with their implementation of relative path logicsession.config.rootdir
. Seehttps://github.com/pytest-dev/pytest/discussions/9807 for details.