将zope.testrunner风格的测试层集成到pytest框架中
项目描述
zope.pytestlayer发行版
将zope.testrunner风格的测试层集成到pytest框架中
此软件包与Python 3.7 - 3.12版本兼容,包括PyPy3。
它之前被称为gocept.pytestlayer。
快速入门
确保您的测试文件遵循pytest测试发现约定
特别是,名为tests.py的文件将不被识别。
添加buildout部分以创建pytest运行器
[buildout] parts += pytest [pytest] recipe = zc.recipe.egg eggs = zope.pytestlayer pytest <YOUR PACKAGE HERE>
zope.pytestlayer将自己注册为pytest插件。这样,就不需要更多的操作来运行现有的Zope或Plone测试套件。
高级使用
版本2.1重新引入了fixture.create()以定义生成到pytest fixtures的名称。因此,它们可以在函数式测试中使用。
示例(代码必须在contest.py中!)
from .testing import FUNCTIONAL_LAYER import zope.pytestlayer.fixture globals().update(zope.pytestlayer.fixture.create( FUNCTIONAL_LAYER, session_fixture_name='functional_session', class_fixture_name='functional_class', function_fixture_name='functional'))
这将在给定的名称和作用域参数中创建三个固定装置。会话和类固定装置在层之前未运行时运行 setUp() 和 tearDown(),而函数固定装置运行层的 testSetUp() 和 testTearDown()。函数固定装置依赖于会话固定装置。固定装置返回层的实例。因此,您可以使用 functional 固定装置如下所示
def test_mymodule__my_function__1(functional): assert functional['app'] is not None
不支持的使用案例
在更改层的同时继承基类。请参阅提交 f879f9e。
在单个模块(即文件)中混合继承自 unittest.TestCase 的类和 test_suite() 函数(例如创建 DocTestSuite 或 DocFileSuite)。
这是 pytest 测试发现的一个限制,它忽略了这种情况下的 doctests。
解决方案:将类和 test_suite() 放入不同的模块中。
没有层的 doctest.DocFileSuite 将被静默跳过。使用 pytest 的内置 doctest 功能来运行这些测试。
开发 zope.pytestlayer
- 作者::
gocept, Godefroid Chapelle <gotcha@bubblenet.be>
- PyPI 页面::
- 问题::
- 源代码::
- 当前更改日志::
https://raw.githubusercontent.com/zopefoundation/zope.pytestlayer/master/CHANGES.rst
zope.pytestlayer 的更改日志
8.2 (2024-05-15)
使测试与 pytest >= 7.3 兼容。(注意:我们目前不支持 pytest >= 8)
添加对 Python 3.11 的支持。
添加对 Python 3.12 的支持。
从 gocept.pytestlayer 重命名为 zope.pytestlayer。
8.1 (2022-09-05)
确保与 pytest >= 7.1.3 兼容。现在 .layered.LayeredTestCaseInstance 必须继承自 _pytest.unittest.UnitTestCase。
8.0 (2021-12-13)
使用 GitHub actions 作为 CI。
添加对 Python 3.9 和 3.10 的支持。
停止对 Python 3.6 的支持。
添加一个绕过问题 #4 的解决方案:使用 gcoept.pytestlayer.doctest.DocTestSuite 而不是 doctest.DocTestSuite 来规避问题。
7.0 (2020-08-03)
向后不兼容的更改
停止对 Python 2.7 和 3.5 以及 pytest < 5.0 的支持。(#8)
特性
支持 pytest >= 6.0。(#8)
6.3 (2020-05-15)
确保与 pytest > 5.4.2 兼容。现在我们 LayeredTestCaseFunction 需要 _explicit_tearDown。
6.2 (2020-03-20)
确保与 pytest > 5.4 兼容。现在我们 LayeredTestCaseFunction 需要 _needs_explicit_tearDown。
6.1 (2020-02-20)
修复测试,使其能够与 pytest >= 4.2.0 运行。
迁移到 Github。
当使用 pytest-rerunfailures 重新运行 doctest 时,不要破坏。
添加对 Python 3.8 的支持。
6.0 (2018-10-24)
添加对 Python 3.6、3.7 和 PyPy3 的支持。
停止对 Python 3.4 的支持。
修复测试,使其能够与 pytest >= 3.9.1 运行。
也作为通用 wheel 发布。
更新到新的 pytest 固定装置 API 以避免 DeprecationWarnings。(#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 兼容。
停止对 Python 2.6 的支持。
2.1 (2014-10-22)
更新 py.test-2.5 的关键字和 doctest 测试名称的处理。[wosc]
重新引入 gocept.pytestlayer.fixture.create() 方法,允许为创建的固定装置提供非随机名称,以便其他固定装置可以依赖于它们。[tlotze, wosc]
除了类级别的,还可以从层生成会话级别的配置文件。如果某处需要会话级别的配置文件,类级别的配置文件将直接被忽略。[tlotze, wosc]
2.0 (2013-09-19)
不需要显式创建配置文件。[gotcha]
添加了对plone.testing.layered测试套件的 支持。[gotcha]
使测试更加健壮。[icemac]
1.0 (2013-08-28)
首次发布。[tlotze, icemac, gotcha]
项目详情
下载文件
下载适用于您平台的文件。如果您不确定该选择哪个,请了解更多关于安装包的信息。
源代码分发
构建分发
zope.pytestlayer-8.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 15b5a862f595cc3844dec506a52968c60b572b3d0cfa320d7caf9bad97d5eb54 |
|
MD5 | 029fd49a53103a2bb337f0f64d49afe5 |
|
BLAKE2b-256 | cb99ecc0b4aeb9072edde6e2ccf5c1b9498d16e86d1e456191c9bd828598a1d0 |
zope.pytestlayer-8.2-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c0e6e26811fd909fa1fa9dddbae0842663b6fb1a4dd6b814abac4639b1cde7c1 |
|
MD5 | 38be24080697d1aa63c0ae67307cb29d |
|
BLAKE2b-256 | f49451b0032b171e82e3d1019a95f32a97e7381a3d5b0aafc85e915ec7413413 |