Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
7234c717
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,发现更多精彩内容 >>
提交
7234c717
编写于
9月 18, 2015
作者:
L
Lucas Meneghel Rodrigues
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #789 from ldoktor/nasty_exc
avocado.core.test: Avoid passing ugly exceptions
上级
5d37cfc3
73c8cefb
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
49 addition
and
5 deletion
+49
-5
avocado/core/test.py
avocado/core/test.py
+10
-5
examples/tests/failtest_nasty3.py
examples/tests/failtest_nasty3.py
+32
-0
selftests/functional/test_standalone.py
selftests/functional/test_standalone.py
+7
-0
未找到文件。
avocado/core/test.py
浏览文件 @
7234c717
...
...
@@ -359,8 +359,9 @@ class Test(unittest.TestCase):
except
exceptions
.
TestNAError
,
details
:
stacktrace
.
log_exc_info
(
sys
.
exc_info
(),
logger
=
'avocado.test'
)
raise
exceptions
.
TestNAError
(
details
)
except
Exception
,
details
:
except
:
# Old-style exceptions are not inherited from Exception()
stacktrace
.
log_exc_info
(
sys
.
exc_info
(),
logger
=
'avocado.test'
)
details
=
sys
.
exc_info
()[
1
]
raise
exceptions
.
TestSetupFail
(
details
)
try
:
testMethod
()
...
...
@@ -371,8 +372,11 @@ class Test(unittest.TestCase):
'must fix your test. Original skip exception: '
'%s'
%
details
)
raise
exceptions
.
TestError
(
skip_illegal_msg
)
except
Exception
,
details
:
except
:
# Old-style exceptions are not inherited from Exception()
stacktrace
.
log_exc_info
(
sys
.
exc_info
(),
logger
=
'avocado.test'
)
details
=
sys
.
exc_info
()[
1
]
if
not
isinstance
(
details
,
Exception
):
# Avoid passing nasty exc
details
=
exceptions
.
TestError
(
"%r: %s"
%
(
details
,
details
))
test_exception
=
details
finally
:
try
:
...
...
@@ -384,9 +388,10 @@ class Test(unittest.TestCase):
'you must fix your test. Original skip '
'exception: %s'
%
details
)
raise
exceptions
.
TestError
(
skip_illegal_msg
)
except
Exception
,
details
:
except
:
# avoid old-style exception failures
stacktrace
.
log_exc_info
(
sys
.
exc_info
(),
logger
=
'avocado.test'
)
cleanup_exception
=
details
details
=
sys
.
exc_info
()[
1
]
cleanup_exception
=
exceptions
.
TestSetupFail
(
details
)
whiteboard_file
=
os
.
path
.
join
(
self
.
logdir
,
'whiteboard'
)
genio
.
write_file
(
whiteboard_file
,
self
.
whiteboard
)
...
...
@@ -423,7 +428,7 @@ class Test(unittest.TestCase):
if
test_exception
is
not
None
:
raise
test_exception
elif
cleanup_exception
is
not
None
:
raise
exceptions
.
TestSetupFail
(
cleanup_exception
)
raise
cleanup_exception
elif
stdout_check_exception
is
not
None
:
raise
stdout_check_exception
elif
stderr_check_exception
is
not
None
:
...
...
examples/tests/failtest_nasty3.py
0 → 100755
浏览文件 @
7234c717
#!/usr/bin/python
from
avocado
import
Test
from
avocado
import
main
class
NastyException
:
""" Please never use something like this!!! (old-style exception) """
def
__init__
(
self
,
msg
):
self
.
msg
=
msg
def
__str__
(
self
):
return
self
.
msg
class
FailTest
(
Test
):
"""
This test raises old-style-class exception
"""
def
test
(
self
):
"""
Should fail not-that-badly
"""
raise
NastyException
(
"Nasty-string-like-exception"
)
if
__name__
==
"__main__"
:
main
()
selftests/functional/test_standalone.py
浏览文件 @
7234c717
...
...
@@ -62,6 +62,13 @@ class StandaloneTests(unittest.TestCase):
self
.
assertIn
(
"Exception: Unable to get exception, check the traceback"
" for details."
,
result
.
stdout
)
def
test_failtest_nasty3
(
self
):
cmd_line
=
'./examples/tests/failtest_nasty3.py -r'
expected_rc
=
1
result
=
self
.
run_and_check
(
cmd_line
,
expected_rc
,
'failtest_nasty3'
)
self
.
assertIn
(
"TestError: <failtest_nasty3.NastyException instance at "
,
result
.
stdout
)
def
test_errortest
(
self
):
cmd_line
=
'./examples/tests/errortest.py -r'
expected_rc
=
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录