Pytest Helpers Namespace

2021.12.29 · maintenance · verified Thu Apr 16

pytest-helpers-namespace is a pytest plugin that provides a convenient namespace to register helper functions in your `conftest.py` file. This allows you to use these helper functions directly within your tests without needing explicit imports, simplifying test code and promoting reusability. The current version is 2021.12.29, and releases are generally infrequent, indicating a mature and stable but not actively developed project.

Common errors

Warnings

Install

Imports

Quickstart

Define helper functions in your `conftest.py` using the `@pytest.helpers.register` decorator. These helpers, including nested ones, become available via `pytest.helpers` in your test functions without explicit imports. The `pytest_plugins = ['helpers_namespace']` declaration in `conftest.py` ensures the plugin is loaded.

import pytest

# conftest.py
# This line ensures the plugin is loaded if not automatically discovered
pytest_plugins = ['helpers_namespace']

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

@pytest.helpers.can.haz.register
def nested_helper(value):
    return f'Nested: {value}'

# test_example.py
def test_helper_namespace():
    assert pytest.helpers.foo(True) is True
    assert pytest.helpers.can.haz.nested_helper('test') == 'Nested: test'

view raw JSON →