将zope.testrunner风格的测试层集成到py.test框架中
gocept.pytestlayer的Python项目详细描述
gocept.pytestlayer分布
将zope.testrunner样式的测试层集成到py.test 框架
这个包与python版本2.7和3.5-3.7兼容,包括 Pypy实现。(若要成功运行其测试,至少应使用 Python2.7.4,因为在早期的Python2.7版本中有一个bug。)
快速启动
确保您的测试文件遵循conventions of py.test’s test discovery
尤其是名为tests.py的文件将无法识别。
添加构建部分以创建py.testrunner:
[buildout] parts += pytest [pytest] recipe = zc.recipe.egg eggs = gocept.pytestlayer pytest <YOUR PACKAGE HERE>
gocept.pytestlayer将自身注册为py.test插件。这边,没什么 需要更多的运行现有的Zope或PLON测试套件。
高级使用
版本2.1重新引入了fixture.create()来定义生成到py.test fixture的名称。因此可以在函数样式测试中使用它们。
示例(代码必须在contest.py中!):
from .testing import FUNCTIONAL_LAYER import gocept.pytestlayer.fixture globals().update(gocept.pytestlayer.fixture.create( FUNCTIONAL_LAYER, session_fixture_name='functional_session', class_fixture_name='functional_class', function_fixture_name='functional'))
这将创建三个fixture,它们具有给定的名称和参数名中的作用域。当函数fixture运行层的testsetup()和testteardown()时,会话和类fixture运行层的setup()和testteardown()。函数fixture依赖于会话1。设备将返回图层的实例。因此,您可以使用类似这样的函数设备:
def test_mymodule__my_function__1(functional): assert functional['app'] is not None
不支持的用例
- 在更改层时从基类继承。见issue #5
- 这是py.test测试发现的一个限制,它忽略了本例中的doctests。
- 解决方案:将类和test_suite()放入不同的模块中。
开发gocept.pytestlayer
Author: | gocept <mail@gocept.com>, Godefroid Chapelle <gotcha@bubblenet.be> |
---|---|
PyPI page: | http://pypi.python.org/pypi/gocept.pytestlayer/ |
Issues: | https://bitbucket.org/gocept/gocept.pytestlayer/issues |
Source code: | https://bitbucket.org/gocept/gocept.pytestlayer/ |
Current change log: | |
https://bitbucket.org/gocept/gocept.pytestlayer/raw/tip/CHANGES.rst |
更改gocept.pytestlayer的日志
6.0(2018-10-24)
- 添加对Python3.6、3.7和PyPy3的支持。
- 放弃对Python3.4的支持。
- 修复要在pytest>;=3.9.1下运行的测试。
- 也作为万向轮松开。
- 更新到新的pytest fixture api以避免deprecationwarning。(10)
5.1(2016-12-02)
- 使安装过程与setuptools=30.0兼容。
5.0(2016-08-23)
- 如果使用pytest>;=3.0进行测试,则修复要通过的测试。
4.0(2016-04-27)
- 支持python 3.4、3.5和pypy。
- 使用tox作为测试运行程序。
3.0(2016-04-14)
- 声明与py.test 2.9.x兼容。
- 放弃Python2.6支持。
2.1(2014-10-22)
- 更新py.test-2.5的关键字和doctest测试名的处理。 [WOSC]
- 重新引入gocept.pytestlayer.fixture.create()方法,以允许 创建了一个非随机名称的装置,因此其他装置可以依赖它们。 [tlotze,wosc]
- 除了类范围的fixture之外,还从层生成会话范围的fixture 如果某个地方需要一个会话范围的,则类范围的 只是被忽略了。[tlotze,wosc]
2.0(2013-09-19)
- 删除需要明确创建夹具。 [明白]
- 添加plone.testing.layered测试套件支持。 [明白]
- 使测试更加健壮。 [ICEMAC]
1.0(2013-08-28)
- 初次发布。 [特洛兹,冰天雪地,明白]