Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
1c3458db
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
1c3458db
编写于
4月 17, 2020
作者:
I
Ilya Yatsishin
提交者:
GitHub
4月 17, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10323 from qoega/junit_to_html_util
Convert test results to JSONEachRow format
上级
d57dea3e
ee8e855c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
10 deletion
+73
-10
tests/integration/pytest.ini
tests/integration/pytest.ini
+1
-0
utils/junit_to_html/junit_to_html
utils/junit_to_html/junit_to_html
+72
-10
未找到文件。
tests/integration/pytest.ini
浏览文件 @
1c3458db
...
...
@@ -3,3 +3,4 @@ python_files = test*.py
norecursedirs
=
_instances
timeout
=
300
junit_duration_report
=
call
junit_suite_name
=
integration
utils/junit_to_html/junit_to_html
浏览文件 @
1c3458db
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
os
import
sys
import
lxml.etree
as
etree
import
json
import
argparse
def
_convert_junit_to_html
(
junit_path
,
html_path
):
def
export_testcases_json
(
report
,
path
):
with
open
(
os
.
path
.
join
(
path
,
"cases.jer"
),
"w"
)
as
testcases_file
:
for
testsuite
in
report
.
getroot
():
for
testcase
in
testsuite
:
row
=
{}
row
[
"hostname"
]
=
testsuite
.
get
(
"hostname"
)
row
[
"suite"
]
=
testsuite
.
get
(
"name"
)
row
[
"suite_duration"
]
=
testsuite
.
get
(
"time"
)
row
[
"timestamp"
]
=
testsuite
.
get
(
"timestamp"
)
row
[
"testname"
]
=
testcase
.
get
(
"name"
)
row
[
"classname"
]
=
testcase
.
get
(
"classname"
)
row
[
"file"
]
=
testcase
.
get
(
"file"
)
row
[
"line"
]
=
testcase
.
get
(
"line"
)
row
[
"duration"
]
=
testcase
.
get
(
"time"
)
for
el
in
testcase
:
if
el
.
tag
==
"system-err"
:
row
[
"stderr"
]
=
el
.
text
else
:
row
[
"stderr"
]
=
""
if
el
.
tag
==
"system-out"
:
row
[
"stdout"
]
=
el
.
text
else
:
row
[
"stdout"
]
=
""
json
.
dump
(
row
,
testcases_file
)
testcases_file
.
write
(
"
\n
"
)
def
export_testsuites_json
(
report
,
path
):
with
open
(
os
.
path
.
join
(
path
,
"suites.jer"
),
"w"
)
as
testsuites_file
:
for
testsuite
in
report
.
getroot
():
row
=
{}
row
[
"suite"
]
=
testsuite
.
get
(
"name"
)
row
[
"errors"
]
=
testsuite
.
get
(
"errors"
)
row
[
"failures"
]
=
testsuite
.
get
(
"failures"
)
row
[
"hostname"
]
=
testsuite
.
get
(
"hostname"
)
row
[
"skipped"
]
=
testsuite
.
get
(
"skipped"
)
row
[
"duration"
]
=
testsuite
.
get
(
"time"
)
row
[
"timestamp"
]
=
testsuite
.
get
(
"timestamp"
)
json
.
dump
(
row
,
testsuites_file
)
testsuites_file
.
write
(
"
\n
"
)
def
_convert_junit_to_html
(
junit_path
,
result_path
,
export_cases
,
export_suites
):
with
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"junit-noframes.xsl"
))
as
xslt_file
:
junit_to_html_xslt
=
etree
.
parse
(
xslt_file
)
if
not
os
.
path
.
exists
(
result_path
):
os
.
makedirs
(
result_path
)
with
open
(
junit_path
)
as
junit_file
:
junit_xml
=
etree
.
parse
(
junit_file
)
if
export_suites
:
export_testsuites_json
(
junit_xml
,
result_path
)
if
export_cases
:
export_testcases_json
(
junit_xml
,
result_path
)
transform
=
etree
.
XSLT
(
junit_to_html_xslt
)
html
=
etree
.
tostring
(
transform
(
junit_xml
),
encoding
=
"utf-8"
)
html_dir
=
os
.
path
.
dirname
(
html_path
)
if
not
os
.
path
.
exists
(
html_dir
):
os
.
makedirs
(
html_dir
)
with
open
(
html_path
,
"w"
)
as
html_file
:
with
open
(
os
.
path
.
join
(
result_path
,
"result.html"
),
"w"
)
as
html_file
:
html_file
.
write
(
html
)
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
<
3
:
raise
"Insufficient arguments: junit.xml result.html"
,
level
junit_path
,
html_path
=
sys
.
argv
[
1
]
,
sys
.
argv
[
2
]
_convert_junit_to_html
(
junit_path
,
html_path
)
parser
=
argparse
.
ArgumentParser
(
description
=
'Convert JUnit XML.'
)
parser
.
add_argument
(
'junit'
,
help
=
'path to junit.xml report'
)
parser
.
add_argument
(
'result_dir'
,
nargs
=
'?'
,
help
=
'directory for result files. Default to junit.xml directory'
)
parser
.
add_argument
(
'--export-cases'
,
help
=
'Export JSONEachRow result for testcases to upload in CI'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--export-suites'
,
help
=
'Export JSONEachRow result for testsuites to upload in CI'
,
action
=
'store_true'
)
args
=
parser
.
parse_args
()
junit_path
=
args
.
junit
if
args
.
result_dir
:
result_path
=
args
.
result_dir
else
:
result_path
=
os
.
path
.
dirname
(
junit_path
)
print
"junit_path: {}, result_path: {}, export cases:{}, export suites: {}"
.
format
(
junit_path
,
result_path
,
args
.
export_cases
,
args
.
export_suites
)
_convert_junit_to_html
(
junit_path
,
result_path
,
args
.
export_cases
,
args
.
export_suites
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录