Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
5cfb159e
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5cfb159e
编写于
4月 23, 2014
作者:
L
Lucas Meneghel Rodrigues
提交者:
Lucas Meneghel Rodrigues
4月 23, 2014
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #27 from ruda/test_result_junit
plugins.xunit: Add class XmlResult.
上级
e3106632
4d0ee940
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
93 addition
and
23 deletion
+93
-23
avocado/plugins/xunit.py
avocado/plugins/xunit.py
+91
-21
tests/failtest/failtest.py
tests/failtest/failtest.py
+2
-2
未找到文件。
avocado/plugins/xunit.py
浏览文件 @
5cfb159e
...
@@ -14,10 +14,85 @@
...
@@ -14,10 +14,85 @@
"""xUnit module."""
"""xUnit module."""
import
sys
import
datetime
from
avocado.plugins
import
plugin
from
avocado.plugins
import
plugin
from
avocado.result
import
TestResult
from
avocado.result
import
TestResult
class
XmlResult
(
object
):
"""
Handles the XML details for xUnit output.
"""
def
__init__
(
self
):
self
.
xml
=
[
'<?xml version="1.0" encoding="UTF-8"?>'
]
def
_escape_cdata
(
self
,
cdata
):
return
cdata
.
replace
(
']]>'
,
']]>]]><![CDATA['
)
def
save
(
self
,
filename
):
xml
=
'
\n
'
.
join
(
self
.
xml
)
if
filename
==
'-'
:
sys
.
stdout
.
write
(
xml
)
else
:
with
open
(
filename
,
'w'
)
as
fresult
:
fresult
.
write
(
xml
)
def
start_testsuite
(
self
,
timestamp
):
self
.
testsuite
=
'<testsuite name="avocado" tests="{tests}" errors="{errors}" failures="{failures}" skip="{skip}" time="{total_time}" timestamp="%s">'
%
timestamp
self
.
testcases
=
[]
def
end_testsuite
(
self
,
tests
,
errors
,
failures
,
skip
,
total_time
):
values
=
{
'tests'
:
tests
,
'errors'
:
errors
,
'failures'
:
failures
,
'skip'
:
skip
,
'total_time'
:
total_time
}
self
.
xml
.
append
(
self
.
testsuite
.
format
(
**
values
))
for
tc
in
self
.
testcases
:
self
.
xml
.
append
(
tc
)
self
.
xml
.
append
(
'</testsuite>'
)
def
add_success
(
self
,
test
):
tc
=
'
\t
<testcase classname="{class}" name="{name}" time="{time}"/>'
values
=
{
'class'
:
test
.
__class__
.
__name__
,
'name'
:
test
.
tagged_name
,
'time'
:
test
.
time_elapsed
}
self
.
testcases
.
append
(
tc
.
format
(
**
values
))
def
add_skip
(
self
,
test
):
tc
=
'''
\t
<testcase classname="{class}" name="{name}" time="{time}">
\t\t
<skipped />
\t
</testcase>'''
values
=
{
'class'
:
test
.
__class__
.
__name__
,
'name'
:
test
.
tagged_name
,
'time'
:
test
.
time_elapsed
}
self
.
testcases
.
append
(
tc
.
format
(
**
values
))
def
add_failure
(
self
,
test
):
tc
=
'''
\t
<testcase classname="{class}" name="{name}" time="{time}">
\t\t
<failure><![CDATA[{reason}]]></failure>
\t
</testcase>'''
values
=
{
'class'
:
test
.
__class__
.
__name__
,
'name'
:
test
.
tagged_name
,
'time'
:
test
.
time_elapsed
,
'reason'
:
self
.
_escape_cdata
(
str
(
test
.
fail_reason
))}
self
.
testcases
.
append
(
tc
.
format
(
**
values
))
def
add_error
(
self
,
test
):
tc
=
'''
\t
<testcase classname="{class}" name="{name}" time="{time}">
\t\t
<error><![CDATA[{reason}]]></error>
\t
</testcase>'''
values
=
{
'class'
:
test
.
__class__
.
__name__
,
'name'
:
test
.
tagged_name
,
'time'
:
test
.
time_elapsed
,
'reason'
:
self
.
_escape_cdata
(
str
(
test
.
fail_reason
))}
self
.
testcases
.
append
(
tc
.
format
(
**
values
))
class
xUnitTestResult
(
TestResult
):
class
xUnitTestResult
(
TestResult
):
"""
"""
...
@@ -30,41 +105,36 @@ class xUnitTestResult(TestResult):
...
@@ -30,41 +105,36 @@ class xUnitTestResult(TestResult):
if
hasattr
(
self
.
args
,
'xunit_output'
):
if
hasattr
(
self
.
args
,
'xunit_output'
):
self
.
filename
=
self
.
args
.
xunit_output
self
.
filename
=
self
.
args
.
xunit_output
else
:
else
:
self
.
filename
=
'
result.xml
'
self
.
filename
=
'
-
'
self
.
xml
=
[
'<?xml version="1.0" encoding="UTF-8"?>'
]
self
.
xml
=
XmlResult
()
def
start_tests
(
self
):
def
start_tests
(
self
):
TestResult
.
start_tests
(
self
)
TestResult
.
start_tests
(
self
)
self
.
xml
.
append
(
'<testsuite name="avocado" '
self
.
xml
.
start_testsuite
(
datetime
.
datetime
.
now
())
'tests="{tests}" errors="{errors}" failures="{failures}" skip="{skip}">'
)
def
start_test
(
self
,
test
):
def
start_test
(
self
,
test
):
TestResult
.
start_test
(
self
,
test
)
TestResult
.
start_test
(
self
,
test
)
def
end_test
(
self
,
test
):
def
end_test
(
self
,
test
):
TestResult
.
end_test
(
self
,
test
)
TestResult
.
end_test
(
self
,
test
)
tc
=
'
\t
<testcase classname="{class}" name="{name}" time="{time}">'
if
test
.
status
==
'PASS'
:
tag
=
test
.
tag
self
.
xml
.
add_success
(
test
)
if
test
.
tag
is
None
:
if
test
.
status
==
'TEST_NA'
:
tag
=
1
self
.
xml
.
add_skip
(
test
)
nametag
=
'%s.%s'
%
(
test
.
name
,
tag
)
if
test
.
status
==
'FAIL'
:
values
=
{
'class'
:
test
.
__class__
.
__name__
,
self
.
xml
.
add_failure
(
test
)
'name'
:
nametag
,
if
test
.
status
==
'ERROR'
:
'time'
:
test
.
time_elapsed
}
self
.
xml
.
add_error
(
test
)
self
.
xml
.
append
(
tc
.
format
(
**
values
))
self
.
xml
.
append
(
'
\t
</testcase>'
)
def
end_tests
(
self
):
def
end_tests
(
self
):
TestResult
.
end_tests
(
self
)
TestResult
.
end_tests
(
self
)
self
.
xml
.
append
(
'</testsuite>'
)
xml
=
'
\n
'
.
join
(
self
.
xml
)
values
=
{
'tests'
:
self
.
tests_total
,
values
=
{
'tests'
:
self
.
tests_total
,
'errors'
:
len
(
self
.
errors
),
'errors'
:
len
(
self
.
errors
),
'failures'
:
len
(
self
.
failed
),
'failures'
:
len
(
self
.
failed
),
'skip'
:
len
(
self
.
skipped
),
}
'skip'
:
len
(
self
.
skipped
),
xml
=
xml
.
format
(
**
values
)
'total_time'
:
self
.
total_time
}
with
open
(
self
.
filename
,
'w'
)
as
fresult
:
self
.
xml
.
end_testsuite
(
**
values
)
fresult
.
write
(
xml
)
self
.
xml
.
save
(
self
.
filename
)
class
XUnit
(
plugin
.
Plugin
):
class
XUnit
(
plugin
.
Plugin
):
...
@@ -80,7 +150,7 @@ class XUnit(plugin.Plugin):
...
@@ -80,7 +150,7 @@ class XUnit(plugin.Plugin):
self
.
parser
=
app_parser
self
.
parser
=
app_parser
app_parser
.
add_argument
(
'--xunit'
,
action
=
'store_true'
)
app_parser
.
add_argument
(
'--xunit'
,
action
=
'store_true'
)
app_parser
.
add_argument
(
'--xunit-output'
,
app_parser
.
add_argument
(
'--xunit-output'
,
default
=
'
result.xml
'
,
type
=
str
,
default
=
'
-
'
,
type
=
str
,
dest
=
'xunit_output'
,
dest
=
'xunit_output'
,
help
=
'the file where the result should be written'
)
help
=
'the file where the result should be written'
)
self
.
configured
=
True
self
.
configured
=
True
...
...
tests/failtest/failtest.py
浏览文件 @
5cfb159e
...
@@ -26,9 +26,9 @@ class failtest(test.Test):
...
@@ -26,9 +26,9 @@ class failtest(test.Test):
Functional test for avocado. Straight up fail the test.
Functional test for avocado. Straight up fail the test.
"""
"""
def
action
(
self
,
length
=
1
):
def
action
(
self
):
"""
"""
S
leep for length seconds
.
S
hould fail
.
"""
"""
raise
exceptions
.
TestFail
(
'This test is supposed to fail'
)
raise
exceptions
.
TestFail
(
'This test is supposed to fail'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录