为什么bamboo junit解析器渲染“未命名测试套件”?

发布于 2025-01-12 21:35:24 字数 210 浏览 3 评论 0原文

我看到几个测试用例出现在竹子 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?

multiple test cases with unnamed test suite

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

起风了 2025-01-19 21:35:24

通过模拟测试结果,我们可以看到,bamboo 至少有两种形式的测试套件命名检测。

显式命名的测试套件

最明智的解析操作发生在显式命名的测试套件下。在 xml 中,这通过 testsuite 标记中的 name 属性显示。

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="test_dummy_suite_name" tests="1" failures="0" errors="0">
    <testcase name="test_dummy_case_name" status="run" duration="0.001" time="1"></testcase>
  </testsuite>
</testsuites>

在这种情况下,bamboo 可以正确解析测试套件的名称,如下所示:
显式命名testsuite

Pytest 生成 xml

Pytest 在生成 junit xml 时,通过 --junit-xml=xml_path.xml 参数,有一个约定,即使用通用名称注入测试套件名称pytest 字符串留在 默认值 junit_suite_name

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite errors="0" failures="1" hostname="XXX" name="pytest" skipped="0" tests="3" time="0.038" timestamp="2022-03-03T17:51:33.038037">
        <testcase classname="classnameX.classnameY" file="junit_explore/test_module.py" line="3" name="test_passing1" time="0.001"></testcase>
        <testcase classname="junit_explore.test_module" file="junit_explore/test_module.py" line="6" name="test_passing2" time="0.000"></testcase>
        <testcase classname="" file="junit_explore/test_module.py" line="6" name="test_passing_empty_classname" time="0.000"></testcase>
    </testsuite>
</testsuites>

Bamboo 似乎熟悉这种约定,并且实际上会回退到解析测试用例的类名属性,以在 . 字符上进行标记,以提取后面的子字符串。请注意上述 xml 的以下输出:

example of test suite name parsed from classname attribute

我们可以看到,对于具有空 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 the testsuite tag.

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="test_dummy_suite_name" tests="1" failures="0" errors="0">
    <testcase name="test_dummy_case_name" status="run" duration="0.001" time="1"></testcase>
  </testsuite>
</testsuites>

In this circumstance bamboo properly parses the testsuite's name as seen here:
explicit named testsuite

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 its junit_suite_name.

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite errors="0" failures="1" hostname="XXX" name="pytest" skipped="0" tests="3" time="0.038" timestamp="2022-03-03T17:51:33.038037">
        <testcase classname="classnameX.classnameY" file="junit_explore/test_module.py" line="3" name="test_passing1" time="0.001"></testcase>
        <testcase classname="junit_explore.test_module" file="junit_explore/test_module.py" line="6" name="test_passing2" time="0.000"></testcase>
        <testcase classname="" file="junit_explore/test_module.py" line="6" name="test_passing_empty_classname" time="0.000"></testcase>
    </testsuite>
</testsuites>

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:

example of test suite name parsed from classname attribute

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 logic session.config.rootdir. See
https://github.com/pytest-dev/pytest/discussions/9807 for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文