Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
aa40fccd
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,发现更多精彩内容 >>
提交
aa40fccd
编写于
10月 03, 2016
作者:
A
Amador Pahim
提交者:
GitHub
10月 03, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1512 from clebergnu/common_test_setup_v2
Docs: document unittest class level setUp and tearDown compatibility
上级
4b3af28c
8837bc4e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
76 addition
and
0 deletion
+76
-0
docs/source/WritingTests.rst
docs/source/WritingTests.rst
+76
-0
未找到文件。
docs/source/WritingTests.rst
浏览文件 @
aa40fccd
...
@@ -992,6 +992,82 @@ Now, trying to list the tests on the ``mytest.py`` file again::
...
@@ -992,6 +992,82 @@ Now, trying to list the tests on the ``mytest.py`` file again::
You can also use the ``:avocado: disable`` tag, that works the opposite way:
You can also use the ``:avocado: disable`` tag, that works the opposite way:
Something looks like an Avocado test, but we force it to not be listed as one.
Something looks like an Avocado test, but we force it to not be listed as one.
Python :mod:`unittest` Compatibility Limitations And Caveats
============================================================
When executing tests, Avocado uses different techniques than most
other Python unittest runners. This brings some compatibility
limitations that Avocado users should be aware.
Execution Model
---------------
One of the main differences is a consequence of the Avocado design
decision that tests should be self contained and isolated from other
tests. Additionally, the Avocado test runner runs each test in a
separate process.
If you have a unittest class with many test methods and run them
using most test runners, you'll find that all test methods run under
the same process. To check that behavior you could add to your
:meth:`setUp <unittest.TestCase.setUp>` method::
def setUp(self):
print("PID: %s", os.getpid())
If you run the same test under Avocado, you'll find that each test
is run on a separate process.
Class Level :meth:`setUp <unittest.TestCase.setUpClass>` and :meth:`tearDown <unittest.TestCase.tearDownClass>`
---------------------------------------------------------------------------------------------------------------
Because of Avocado's test execution model (each test is run on a
separate process), it doesn't make sense to support unittest's
:meth:`unittest.TestCase.setUpClass` and
:meth:`unittest.TestCase.tearDownClass`. Test classes are freshly
instantiated for each test, so it's pointless to run code in those
methods, since they're supposed to keep class state between tests.
If you require a common setup to a number of tests, the current
recommended approach is to to write regular :meth:`setUp
<unittest.TestCase.setUp>` and :meth:`tearDown
<unittest.TestCase.tearDown>` code that checks if a given state was
already set. One example for such a test that requires a binary
installed by a package::
from avocado import Test
from avocado.utils import software_manager
from avocado.utils import path as utils_path
from avocado.utils import process
class BinSleep(Test):
"""
Sleeps using the /bin/sleep binary
"""
def setUp(self):
self.sleep = None
try:
self.sleep = utils_path.find_command('sleep')
except utils_path.CmdNotFoundError:
software_manager.install_distro_packages({'fedora': ['coreutils']})
self.sleep = utils_path.find_command('sleep')
def test(self):
process.run("%s 1" % self.sleep)
If your test setup is some kind of action that will last accross
processes, like the installation of a software package given in the
previous example, you're pretty much covered here.
If you need to keep other type of data a class acrross test
executions, you'll have to resort to saving and restoring the data
from an outside source (say a "pickle" file). Finding and using a
reliable and safe location for saving such data is currently not in
the Avocado supported use cases.
Environment Variables for Simple Tests
Environment Variables for Simple Tests
======================================
======================================
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录