Detailed documentation
**********************
The package works in two steps:
1) It looks for testfiles in a given package.
2) It registers the tests according to your specifications.
Initial notes
=============
* Between version 0.2 and 0.3 of ``z3c.testsetup`` a new set of testfile
markers was introduced. If you are still using ``Test-Layer: unit`` or
similar, please read the README.txt in the source directory carefully to
learn how to switch to the new names. (Or see further down this page when
reading it on pypi).
* Zope integration note: if you want zope integration or functional tests, you
have to make sure, that the ``zope.app.testing`` and ``zope.component``
packages are available during test runs. ``z3c.testsetup`` does **not**
depend on it to make it usable for plain python packages. If you want zope
integration/functional tests, this is almost always already the case, so you
don't need to care about this.
* If you download the source code, you can look at the examples used for
testing and at text files that test technical aspects of z3c.testsetup.
This can be handy when you want detailed knowledge about specific features.
Basic Example
=============
Before we can find, register and execute tests, we first have to write them
down. z3c.testsetup includes examples used for testing (you can find them all
in the ``tests/`` subdirectory if you've downloaded the source code):
>>> import os
>>> import z3c.testsetup
>>> pkgpath = os.path.dirname(z3c.testsetup.__file__)
>>> cavepath = os.path.join(pkgpath, 'tests', 'othercave')
Registering doctests
--------------------
In this example directory, there is a simple doctest ``doctest01.txt`` (please
ignore the pipes on the left):
>>> print_file(os.path.join(cavepath, 'doctest01.txt'))
| A doctest
| =========
|
| :doctest:
|
| This is a simple doctest.
|
| >>> 1+1
| 2
|
Important to note: the doctest is marked by a special marker that tells the
testsetup machinery that the file contains doctest examples that should be
registered during test runs::
:doctest:
Without this marker, a testfile won't be registered during tests! This is the
only difference compared to 'normal' doctests when you use z3c.testsetup. If
you want to disable a test, just turn ``:doctest:`` into ``:nodoctest:`` (or
something else) and the file will be ignored.
.. note:: How to disable markers or make them invisible
All markers can be written as restructured text comments (two leading dots
followed by whitespace) like this::
.. :doctest:
and will still work. This way you can make the markers disappear
from autogenerated docs etc.
Running the tests
-----------------
Now that we have a doctest available, we can write a testsetup routine that
collects all tests, registers them and passes them to the testrunner:
>>> print open(os.path.join(cavepath, 'simplesetup01.py')).read()
import z3c.testsetup
test_suite = z3c.testsetup.register_all_tests(
'z3c.testsetup.tests.othercave')
This is all we need in simple cases. We use
``register_all_tests(<dotted_pkg_name>)`` to tell the setup machinery, where
to look for test files. Note that also files in subpackages will be found,
registered and executed when they are marked approriately.
Let's start the testrunner and see what it gives:
>>> import sys
>>> sys.argv = [sys.argv[0],]
>>> defaults = [
... '--path', cavepath,
... '--tests-pattern', '^simplesetup01$',
... ]
>>> from z3c.testsetup import testrunner
>>> testrunner.run(defaults)
Running z3c...layer.DefaultZCMLLayer [...ftesting.zcml] tests:
Set up z3c...layer.DefaultZCMLLayer [...ftesting.zcml] in 2.146 seconds.
Ran 3 tests with 0 failures and 0 errors in 0.009 seconds.
Running z3c...layer.DefaultZCMLLayer [...ftesting2.zcml] tests:
Tear down z3c...layer.DefaultZCMLLayer [...ftesting.zcml] ... not supported
Running in a subprocess.
Set up z3c...layer.DefaultZCMLLayer [...ftesting2.zcml] in 0.040 seconds.
Ran 1 tests with 0 failures and 0 errors in 0.011 seconds.
Tear down z3c...layer.DefaultZCMLLayer [...ftesting2.zcml] ... not supported
Running z3c.testsetup.tests.othercave.testing.FunctionalLayer1 tests:
Running in a subprocess.
Set up z3c.testsetup.tests.othercave.testing.FunctionalLayer1 in 1.797 seconds.
Ran 1 tests with 0 failures and 0 errors in 0.013 seconds.
Tear down z3c.testsetup.tests.othercave.testing.FunctionalLayer1 in 0.001 seconds.
Running z3c.testsetup.tests.othercave.testing.UnitLayer2 tests:
Running in a subprocess.
Set up z3c.testsetup.tests.othercave.testing.UnitLayer1 in 0.000 seconds.
Set up z3c.testsetup.tests.othercave.testing.UnitLayer2 in 0.000 seconds.
Running testSetUp of UnitLayer1
Running testSetUp of UnitLayer2
Running testTearDown of UnitLayer2
Running testTearDown of UnitLayer1
Ran 1 tests with 0 failures and 0 errors in 0.009 seconds.
Tear down z3c.testsetup.tests.othercave.testing.UnitLayer2 in 0.000 seconds.
Tear down z3c.testsetup.tests.othercave.testing.UnitLayer1 in 0.000 seconds.
Running zope...testrunner.layer.UnitTests tests:
Running in a subprocess.
Set up zope...testrunner.layer.UnitTests in 0.000 seconds.
Custom setUp for <DocTest doctest05.txt from ...doctest05.txt:0 (2 examples)>
Custom tearDown for <DocTest doctest05.txt from ...doctest05.txt:0 (2 examples)>
Ran 4 tests with 0 failures and 0 errors in 0.011 seconds.
Tear down zope...testrunner.layer.UnitTests in 0.000 seconds.
Total: 10 tests, 0 failures, 0 errors in 11.798 seconds.
False
As we can see, there were regular unittests as well as functional tests
run. Some of the unittests used their own layer (``UnitLayer1``). Layers are
shown in the output. In this example, the functional tests use different
ZCML-files for configuration which results in separate test layers.
Finding doctests in Python modules
----------------------------------
The doctest file described above was a pure .txt file. By default
``z3c.testsetup`` looks for doctests in files with filename extension
``.txt``, ``.rst`` and ``.py``. This means, that also doctests in
Python modules are found just fine as in the following example:
>>> print_file(os.path.join(cavepath, 'doctest08.py'))
| """
| Doctests in a Python module
| ===========================
|
| We can place doctests also in Python modules.
|
| :doctest:
|
| Here the Cave class is defined::
|
| >>> from z3c.testsetup.tests.othercave.doctest08 import Cave
| >>> Cave
| <class 'z3c.testsetup...doctest08.Cave'>
|
| """
| class Cave(object):
| """A Cave.
|
| A cave has a number::
|
| >>> hasattr(Cave, 'number')
| True
|
| """
| number = None
|
| def __init__(self, number):
| """Create a Cave.
|
| We have to give a number if we create a cave::
|
| >>> c = Cave(12)
| >>> c.number
| 12
|
| """
| self.number = number
|
Here we placed the marker string ``:doctest:`` into the docstring of
the module. Without it, the module would not have been considered a
testfile.
Note that you have to import the entities (classes, functions, etc.)
from the very same file if you want to use them.
Registering regular python unittests
------------------------------------
``z3c.testsetup`` provides also (limited) support for regular
``unittest`` deployments as usually written in Python. An example file
looks like this:
>>> print_file(os.path.join(cavepath, 'pythontest1.py'))
| """
| Tests with real TestCase objects.
|
| :unittest:
|
| """
|
| import unittest
|
| class TestTest(unittest.TestCase):
|
| def setUp(self):
没有合适的资源?快使用搜索试试~ 我知道了~
PyPI 官网下载 | z3c.testsetup-0.8.1.tar.gz
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 158 浏览量
2022-01-17
15:13:26
上传
评论
收藏 82KB GZ 举报
温馨提示
共109个文件
py:49个
txt:41个
zcml:10个
资源来自pypi官网。 资源全名:z3c.testsetup-0.8.1.tar.gz
资源推荐
资源详情
资源评论
收起资源包目录
PyPI 官网下载 | z3c.testsetup-0.8.1.tar.gz (109个子文件)
buildout.cfg 341B
setup.cfg 59B
checkertest.chk 350B
globstest.chk 297B
notatest1.foo 122B
not-zip-safe 1B
PKG-INFO 42KB
PKG-INFO 42KB
doctesting.py 9KB
newbootstrap.py 7KB
test_testsetup.py 6KB
testgetter.py 5KB
doctesting.py 5KB
base.py 4KB
testing.py 4KB
bootstrap.py 4KB
testing.py 3KB
util.py 3KB
layer.py 2KB
testgetter.py 2KB
setup.py 2KB
testrunner.py 1KB
__init__.py 1KB
layer.py 919B
doctest08.py 645B
samplesetup1.py 464B
samplesetup_short5.py 429B
samplesetup_short8.py 289B
samplesetup_short9.py 289B
samplesetup_short7.py 288B
__init__.py 274B
samplesetup2.py 273B
__init__.py 248B
samplesetup_short6.py 219B
__init__.py 214B
file1.py 210B
notatest2.py 209B
__init__.py 204B
pythontest1.py 201B
samplesetup_teardown.py 197B
broken_test_mod2.py 175B
samplesetup_short4.py 171B
broken_mod.py 142B
broken_test_mod.py 141B
layeredsetup01.py 113B
samplesetup_short2.py 110B
samplesetup_short3.py 109B
simplesetup01.py 105B
samplesetup_short1.py 95B
samplesetup_short0.py 95B
__init__.py 22B
__init__.py 20B
__init__.py 20B
__init__.py 12B
__init__.py 12B
__init__.py 9B
__init__.py 0B
file1.rst 143B
testrunner.txt 26KB
README.txt 26KB
testgetter.txt 17KB
README_OLD.txt 17KB
functionaldoctestsetup.txt 16KB
pythontestsetup.txt 10KB
basicsetup.txt 9KB
unitdoctestsetup.txt 9KB
unittestsetup.txt 7KB
CHANGES.txt 6KB
util.txt 5KB
SOURCES.txt 4KB
nozopeapptesting.txt 4KB
LICENSE.txt 2KB
setupininit.txt 2KB
util.txt 2KB
HOWTO_UPGRADE.txt 1KB
README.txt 910B
DEVELOPMENT.txt 877B
anotherfunctionaldoctest.txt 513B
afunctionaldoctest.txt 512B
doctest06.txt 463B
doctest07.txt 431B
doctest04.txt 333B
doctest09.txt 332B
doctest05.txt 311B
.hiddenfile.txt 244B
afunctionaldoctest.txt 213B
file1.txt 193B
adoctest.txt 178B
doctest02.txt 127B
doctest03.txt 109B
requires.txt 90B
subdirfile.txt 86B
doctest01.txt 73B
COPYRIGHT.txt 32B
namespace_packages.txt 4B
top_level.txt 4B
dependency_links.txt 1B
hiddenfile.txt 0B
file2.TXT 0B
ftesting.zcml 405B
共 109 条
- 1
- 2
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功