Skip to main content

将 zope.testrunner 风格的测试层集成到 pytest 框架中

项目描述

gocept.pytestlayer 分布

https://img.shields.io/pypi/v/gocept.pytestlayer.svg https://img.shields.io/pypi/pyversions/gocept.pytestlayer.svg https://github.com/gocept/gocept.pytestlayer/workflows/tests/badge.svg https://coveralls.io/repos/github/gocept/gocept.pytestlayer/badge.svg?branch=main

将 zope.testrunner 风格的测试层集成到pytest 框架中

这个包与 Python 3.7 - 3.10 版本兼容,包括 PyPy3。

快速开始

  • 确保您的测试文件遵循pytest 的测试发现的约定

    特别是,将无法识别名为tests.py的文件。

  • 添加一个构建部分以创建pytest 运行器

    [buildout]
    parts += pytest
    
    [pytest]
    recipe = zc.recipe.egg
    eggs = gocept.pytestlayer
           pytest
           <YOUR PACKAGE HERE>

gocept.pytestlayer将自己注册为pytest插件。这样,运行现有的 Zope 或 Plone 测试套件就不再需要了。

高级用法

2.1 版重新引入了fixture.create()以便能够将生成的名称定义为 pytest 固定装置。因此可以在函数样式测试中使用它们。

示例(代码必须在match.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 会运行该层的setUp()tearDown() ,而函数fixture 会运行该层的testSetUp()testTearDown()。功能夹具取决于会话一。固定装置返回层的实例。所以你可以像这样使用功能夹具:

def test_mymodule__my_function__1(functional):
    assert functional['app'] is not None

不支持的用例

  • 在更改层时从基类继承。请参阅提交f879f9e

  • 在单个模块(又名文件)中混合继承unittest.TestCasetest_suite()函数的类(例如,创建DocTestSuiteDocFileSuite )。

    • 这是pytest测试发现的一个限制,在这种情况下忽略了 doctest。

    • 解决方案:将classes和test_suite()放到不同的模块中。

  • 一个没有层的doctest.DocFileSuite被静默地跳过。使用 pytest 的内置 doctest 功能来运行这些测试。

开发 gocept.pytestlayer

作者

gocept <邮件@gocept _ com >, Godefroid Chapelle < gotcha @bubblenet 成为>

PyPI 页面

http://pypi.python.org/pypi/gocept.pytestlayer/

问题

https://github.com/gocept/gocept.pytestlayer/issues

源代码

https://github.com/gocept/gocept.pytestlayer

当前更改日志

https://raw.githubusercontent.com/gocept/gocept.pytestlayer/master/CHANGES.rst

gocept.pytestlayer 的更改日志

8.1 (2022-09-05)

  • 确保与 pytest >= 7.1.3 兼容。 .layered.LayeredTestCaseInstance现在必须继承自 _pytest.unittest.UnitTestCase

8.0 (2021-12-13)

  • 将 GitHub 操作用作 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运行。

  • 发布也作为万向轮。

  • 更新到新的 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 测试名称的处理。[沃斯克]

  • 重新引入gocept.pytestlayer.fixture.create()方法,允许给创建的夹具一个非随机的名称,以便其他夹具可以依赖它们。[特洛兹,沃斯克]

  • 除了类范围的夹具之外,还从层生成会话范围的夹具,如果某处需要会话范围的夹具,则简单地忽略类范围的夹具。[特洛兹,沃斯克]

2.0 (2013-09-19)

  • 无需显式创建固定装置。[明白了]

  • 添加plone.testing.layered测试套件支持。[明白了]

  • 使测试更加健壮。[冰点]

1.0 (2013-08-28)

  • 初始发行。[tlotze,icemac,陷阱]

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

gocept.pytestlayer-8.1.tar.gz (24.1 kB 查看哈希

已上传 source

内置分布

gocept.pytestlayer-8.1-py3-none-any.whl (38.0 kB 查看哈希

已上传 py3