【发布时间】:2023-01-26 14:03:59
【问题描述】:
玩弄一个虚拟测试结果,我们可以看到 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 正确解析了测试套件的名称,如下所示:
Pytest生成的xml
Pytest 在通过 --junit-xml=xml_path.xml 参数生成 junit xml 时,有一个约定,即在将测试套件名称留给 default value 以用于其 junit_suite_name 时,使用通用 pytest 字符串注入测试套件名称。
<?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 的以下输出:
我们可以看到,对于具有空类名属性的测试用例,Bamboo 可以稳健地处理该用例,但最终无法确定测试套件名称并回退到 unnamed test suite 表示,因为这是此类测试用例的所有上下文。
背景故事:事实证明,从 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 了解详情。
【讨论】: