Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
ebe788dd
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,发现更多精彩内容 >>
未验证
提交
ebe788dd
编写于
5月 04, 2017
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'apahim/methods_tags_v2'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
32032956
933d6b3b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
103 addition
and
26 deletion
+103
-26
avocado/core/loader.py
avocado/core/loader.py
+31
-25
docs/source/WritingTests.rst
docs/source/WritingTests.rst
+34
-0
selftests/unit/test_loader.py
selftests/unit/test_loader.py
+38
-1
未找到文件。
avocado/core/loader.py
浏览文件 @
ebe788dd
...
...
@@ -32,7 +32,6 @@ from . import test
from
.
import
safeloader
from
..utils
import
path
from
..utils
import
stacktrace
from
..utils
import
data_structures
from
.settings
import
settings
#: Show default tests (for execution)
...
...
@@ -628,14 +627,13 @@ class FileLoader(TestLoader):
# ":avocado: enable" or ":avocado: disable
if
safeloader
.
check_docstring_directive
(
docstring
,
'disable'
):
continue
elif
safeloader
.
check_docstring_directive
(
docstring
,
'enable'
):
methods
=
[
st
.
name
for
st
in
statement
.
body
if
isinstance
(
st
,
ast
.
FunctionDef
)
and
st
.
name
.
startswith
(
'test'
)]
methods
=
data_structures
.
ordered_list_unique
(
methods
)
tags
=
safeloader
.
get_docstring_directives_tags
(
docstring
)
result
[
statement
.
name
]
=
{
'methods'
:
methods
,
'tags'
:
tags
}
cl_tags
=
safeloader
.
get_docstring_directives_tags
(
docstring
)
if
safeloader
.
check_docstring_directive
(
docstring
,
'enable'
):
info
=
self
.
_get_methods_info
(
statement
.
body
,
cl_tags
)
result
[
statement
.
name
]
=
info
continue
if
test_import
:
...
...
@@ -643,13 +641,9 @@ class FileLoader(TestLoader):
if
hasattr
(
base
,
'id'
)]
# Looking for a 'class FooTest(Test):'
if
test_import_name
in
base_ids
:
methods
=
[
st
.
name
for
st
in
statement
.
body
if
isinstance
(
st
,
ast
.
FunctionDef
)
and
st
.
name
.
startswith
(
'test'
)]
methods
=
data_structures
.
ordered_list_unique
(
methods
)
tags
=
safeloader
.
get_docstring_directives_tags
(
docstring
)
result
[
statement
.
name
]
=
{
'methods'
:
methods
,
'tags'
:
tags
}
info
=
self
.
_get_methods_info
(
statement
.
body
,
cl_tags
)
result
[
statement
.
name
]
=
info
continue
# Looking for a 'class FooTest(avocado.Test):'
...
...
@@ -658,16 +652,28 @@ class FileLoader(TestLoader):
module
=
base
.
value
.
id
klass
=
base
.
attr
if
module
==
mod_import_name
and
klass
==
'Test'
:
methods
=
[
st
.
name
for
st
in
statement
.
body
if
isinstance
(
st
,
ast
.
FunctionDef
)
and
st
.
name
.
startswith
(
'test'
)]
methods
=
data_structures
.
ordered_list_unique
(
methods
)
tags
=
safeloader
.
get_docstring_directives_tags
(
docstring
)
result
[
statement
.
name
]
=
{
'methods'
:
methods
,
'tags'
:
tags
}
info
=
self
.
_get_methods_info
(
statement
.
body
,
cl_tags
)
result
[
statement
.
name
]
=
info
return
result
@
staticmethod
def
_get_methods_info
(
statement_body
,
class_tags
):
methods_info
=
[]
for
st
in
statement_body
:
if
(
isinstance
(
st
,
ast
.
FunctionDef
)
and
st
.
name
.
startswith
(
'test'
)):
docstring
=
ast
.
get_docstring
(
st
)
mt_tags
=
safeloader
.
get_docstring_directives_tags
(
docstring
)
mt_tags
.
update
(
class_tags
)
methods
=
[
method
for
method
,
tags
in
methods_info
]
if
st
.
name
not
in
methods
:
methods_info
.
append
((
st
.
name
,
mt_tags
))
return
methods_info
def
_make_avocado_tests
(
self
,
test_path
,
make_broken
,
subtests_filter
,
test_name
=
None
):
if
test_name
is
None
:
...
...
@@ -678,7 +684,7 @@ class FileLoader(TestLoader):
test_factories
=
[]
for
test_class
,
info
in
tests
.
items
():
if
isinstance
(
test_class
,
str
):
for
test_method
in
info
[
'methods'
]
:
for
test_method
,
tags
in
info
:
name
=
test_name
+
\
':%s.%s'
%
(
test_class
,
test_method
)
if
(
subtests_filter
and
...
...
@@ -687,7 +693,7 @@ class FileLoader(TestLoader):
tst
=
(
test_class
,
{
'name'
:
name
,
'modulePath'
:
test_path
,
'methodName'
:
test_method
,
'tags'
:
info
[
'tags'
]
})
'tags'
:
tags
})
test_factories
.
append
(
tst
)
return
test_factories
else
:
...
...
docs/source/WritingTests.rst
浏览文件 @
ebe788dd
...
...
@@ -1356,6 +1356,40 @@ parameter, no test will be included::
$ avocado list perf.py --filter-by-tags=disk,slow,superuser,safe | wc -l
0
Test tags can be applied to test classes and to test methods. Tags are
evaluated per method, meaning that the class tags will be inherited by
all methods, being merged with method local tags. Example::
from avocado import Test
class MyClass(Test):
"""
:avocado: tags=furious
"""
def test1(self):
"""
:avocado: tags=fast
"""
pass
def test2(self):
"""
:avocado: tags=slow
"""
pass
If you use the tag ``furious``, all tests will be included::
$ avocado list furious_tests.py --filter-by-tags=furious
INSTRUMENTED test_tags.py:MyClass.test1
INSTRUMENTED test_tags.py:MyClass.test2
But using ``fast`` and ``furious`` will include only ``test1``::
$ avocado list furious_tests.py --filter-by-tags=fast,furious
INSTRUMENTED test_tags.py:MyClass.test1
Multiple `--filter-by-tags`
~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
selftests/unit/test_loader.py
浏览文件 @
ebe788dd
...
...
@@ -61,12 +61,18 @@ class DisabledTest(Test):
class FastTest(Test):
'''
:avocado: tags=fast
,net
:avocado: tags=fast
'''
def test_fast(self):
'''
:avocado: tags=net
'''
pass
def test_fast_other(self):
'''
:avocado: tags=net
'''
pass
class SlowTest(Test):
...
...
@@ -180,6 +186,26 @@ class Second(avocado.Test):
pass
"""
KEEP_METHODS_ORDER
=
'''
from avocado import Test
class MyClass(Test):
def test2(self):
pass
def testA(self):
pass
def test1(self):
pass
def testZZZ(self):
pass
def test(self):
pass
'''
class
LoaderTest
(
unittest
.
TestCase
):
...
...
@@ -463,6 +489,17 @@ class LoaderTest(unittest.TestCase):
'does,not,exist'
])
self
.
assertEqual
(
len
(
filtered
),
0
)
def
test_methods_order
(
self
):
avocado_keep_methods_order
=
script
.
TemporaryScript
(
'keepmethodsorder.py'
,
KEEP_METHODS_ORDER
)
avocado_keep_methods_order
.
save
()
expected_order
=
[
'test2'
,
'testA'
,
'test1'
,
'testZZZ'
,
'test'
]
tests
=
self
.
loader
.
_find_avocado_tests
(
avocado_keep_methods_order
.
path
)
methods
=
[
method
[
0
]
for
method
in
tests
[
'MyClass'
]]
self
.
assertEqual
(
expected_order
,
methods
)
avocado_keep_methods_order
.
remove
()
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
tmpdir
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录