Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
9df6d22c
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,发现更多精彩内容 >>
未验证
提交
9df6d22c
编写于
4月 17, 2017
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'ldoktor/pre_post_tests_doc2'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
067b74d4
8b53f5a2
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
61 addition
and
14 deletion
+61
-14
avocado/core/data_dir.py
avocado/core/data_dir.py
+8
-0
avocado/plugins/teststmpdir.py
avocado/plugins/teststmpdir.py
+0
-4
docs/source/ReferenceGuide.rst
docs/source/ReferenceGuide.rst
+23
-4
selftests/check_tmp_dirs
selftests/check_tmp_dirs
+1
-1
selftests/functional/test_teststmpdir.py
selftests/functional/test_teststmpdir.py
+2
-0
selftests/functional/test_unittest_compat.py
selftests/functional/test_unittest_compat.py
+3
-0
selftests/run
selftests/run
+15
-1
selftests/unit/test_job.py
selftests/unit/test_job.py
+9
-4
未找到文件。
avocado/core/data_dir.py
浏览文件 @
9df6d22c
...
...
@@ -210,6 +210,14 @@ class _TmpDirTracker(Borg):
"you're trying to provide will have no effect."
)
return
self
.
tmp_dir
def
unittest_refresh_dir_tracker
(
self
):
"""
This force-removes the tmpdir and refreshes the tracker to create new
"""
if
not
hasattr
(
self
,
"tmp_dir"
):
return
shutil
.
rmtree
(
self
.
__dict__
.
pop
(
"tmp_dir"
))
def
__del__
(
self
):
tmp_dir
=
getattr
(
self
,
'tmp_dir'
,
None
)
...
...
avocado/plugins/teststmpdir.py
浏览文件 @
9df6d22c
...
...
@@ -45,7 +45,3 @@ class TestsTmpDir(JobPre, JobPost):
del
os
.
environ
[
self
.
_varname
]
except
:
pass
def
__del__
(
self
):
# Make sure we will cleanup if something bad happens
self
.
post
(
None
)
docs/source/ReferenceGuide.rst
浏览文件 @
9df6d22c
...
...
@@ -363,8 +363,27 @@ The instances should have:
.. [#f1] Avocado plugins can introduce additional test types.
Job Pre and Post Scripts
========================
Pre and post tests plugins
==========================
Avocado supports plug-ins which are (guaranteed to be) executed before the
first test and after all tests finished. The interfaces are
:class:`avocado.core.plugin_interfaces.JobPre`, resp.
:class:`avocado.core.plugin_interfaces.JobPost`.
Note the ``pre_tests`` might not be executed due to earlier failure which
prevents the tests from being executed.
The same applies for ``post_tests``, but it is possible to have ``post_tests``
executed even when ``pre_tests`` were not. Additionally the ``post_tests``
are (obviously) not executed on ``SIGKILL``. On the other hand they are
executed on ``SIGTERM`` and ``KeyboardInterrupt`` while running
the tests, but once the ``post_tests`` are executed the ``KeyboardInterrupt``
or ``SystemExit`` interrupts their processing (to avoid hangs) and remaining
plug-ins will **NOT** be executed.
Jobscripts plugin
-----------------
Avocado ships with a plugin (installed by default) that allows running
scripts before and after the actual execution of Jobs. A user can be
...
...
@@ -373,7 +392,7 @@ been run, and when the "post" scripts are run, all the tests in a
given job have already finished running.
Configuration
-------------
^^^^^^^^^^^^^
By default, the script directory location is::
...
...
@@ -410,7 +429,7 @@ section:
pre or post) exits with non-zero status
Script Execution Environment
----------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
All scripts are run in separate process with some environment
variables set. These can be used in your scripts in any way you wish:
...
...
selftests/check_tmp_dirs
浏览文件 @
9df6d22c
...
...
@@ -24,7 +24,7 @@ def check_tmp_dirs():
dir_to_check
)
except
AssertionError
:
print
(
'There are temporary avocado dirs lying around after test: %s'
,
avocado_tmp_dirs
)
[
os
.
path
.
join
(
dir_to_check
,
_
)
for
_
in
avocado_tmp_dirs
]
)
fail
=
True
if
fail
:
sys
.
exit
(
1
)
...
...
selftests/functional/test_teststmpdir.py
浏览文件 @
9df6d22c
...
...
@@ -94,6 +94,8 @@ class TestsTmpDirTests(unittest.TestCase):
%
(
len
(
content
),
content
))
def
tearDown
(
self
):
self
.
instrumented_test
.
remove
()
self
.
simple_test
.
remove
()
shutil
.
rmtree
(
self
.
tmpdir
)
...
...
selftests/functional/test_unittest_compat.py
浏览文件 @
9df6d22c
...
...
@@ -110,6 +110,9 @@ class UnittestCompat(unittest.TestCase):
self
.
assertIn
(
'FAILED (errors=1)'
,
result
.
stderr
)
def
tearDown
(
self
):
self
.
unittest_script_error
.
remove
()
self
.
unittest_script_fail
.
remove
()
self
.
unittest_script_good
.
remove
()
shutil
.
rmtree
(
self
.
tmpdir
)
...
...
selftests/run
浏览文件 @
9df6d22c
...
...
@@ -8,7 +8,12 @@ import sys
import
logging
import
unittest
from
avocado.core
import
data_dir
logger
=
logging
.
getLogger
(
__name__
)
CHECK_TMP_DIRS
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"check_tmp_dirs"
))
def
test_suite
():
...
...
@@ -22,8 +27,17 @@ def test_suite():
return
suite
class
MyResult
(
unittest
.
TextTestResult
):
def
startTest
(
self
,
test
):
# Destroy the data_dir.get_tmpdir
data_dir
.
_tmp_tracker
.
unittest_refresh_dir_tracker
()
assert
os
.
system
(
CHECK_TMP_DIRS
)
==
0
,
"Previous test left some dirs behind"
return
super
(
MyResult
,
self
).
startTest
(
test
)
if
__name__
==
'__main__'
:
runner
=
unittest
.
TextTestRunner
(
failfast
=
not
os
.
environ
.
get
(
"SELF_CHECK_CONTINUOUS"
))
runner
=
unittest
.
TextTestRunner
(
failfast
=
not
os
.
environ
.
get
(
"SELF_CHECK_CONTINUOUS"
),
verbosity
=
2
,
resultclass
=
MyResult
)
result
=
runner
.
run
(
test_suite
())
if
result
.
failures
or
result
.
errors
:
sys
.
exit
(
1
)
selftests/unit/test_job.py
浏览文件 @
9df6d22c
...
...
@@ -70,7 +70,10 @@ class JobTest(unittest.TestCase):
logdir
=
self
.
tmpdir
)
myjob
=
JobFilterTime
(
args
)
myjob
.
create_test_suite
()
myjob
.
pre_tests
()
try
:
myjob
.
pre_tests
()
finally
:
myjob
.
post_tests
()
self
.
assertLessEqual
(
len
(
myjob
.
test_suite
),
1
)
def
test_job_run_tests
(
self
):
...
...
@@ -93,9 +96,11 @@ class JobTest(unittest.TestCase):
logdir
=
self
.
tmpdir
)
myjob
=
JobLogPost
(
args
)
myjob
.
create_test_suite
()
myjob
.
pre_tests
()
myjob
.
run_tests
()
myjob
.
post_tests
()
try
:
myjob
.
pre_tests
()
myjob
.
run_tests
()
finally
:
myjob
.
post_tests
()
self
.
assertEqual
(
myjob
.
unique_id
[::
-
1
],
open
(
os
.
path
.
join
(
myjob
.
logdir
,
"reversed_id"
)).
read
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录