跳转到主要内容

Pytest Helper命名空间插件

项目描述

See Build Status Code Coverage PyPI Package latest release PyPI Package monthly downloads PyPI Wheel Supported versions Supported implementations

Pytest Helper命名空间

此插件不提供任何帮助程序给pytest,但它确实在pytest中提供了一个帮助程序命名空间,允许您在conftest.py中注册帮助函数,以便在测试中使用,而无需导入。

功能

  • 提供了一个可用的pytest命名空间,可用于注册帮助函数,而无需在您的实际测试中导入它们。

要求

  • 无!

安装

您可以通过从PyPI使用pip安装“pytest-helpers-namespace”

$ pip install pytest-helpers-namespace

使用方法

考虑以下conftest.py文件

import pytest


@pytest.helpers.register
def foo(bar):
    """
    this dumb helper function will just return what you pass to it
    """
    return bar

现在考虑以下测试用例

def test_helper_namespace():
    assert pytest.helpers.foo(True) is True

很简单,对吧?

您甚至可以嵌套命名空间。考虑以下conftest.py文件

pytest_plugins = ["helpers_namespace"]

import pytest


@pytest.helpers.can.haz.register
def foo(bar):
    """
    this dumb helper function will just return what you pass to it
    """
    return bar

现在考虑以下测试用例

def test_helper_namespace():
    assert pytest.helpers.can.haz.foo(True) is True

您甚至可以向注册函数传递一个名称,这将成为辅助函数的名称。


Pytest 插件是与Cookiecutter以及@hackebrotCookiecutter-pytest-plugin模板一起生成的。

文档

完整文档可以在此处查看。

项目详情


下载文件

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

源分布

pytest-helpers-namespace-2021.12.29.tar.gz (53.4 kB 查看哈希值)

上传时间

构建分布

pytest_helpers_namespace-2021.12.29-py3-none-any.whl (10.5 kB 查看哈希值)

上传时间 Python 3

支持者