Registry / testing / pytest-helpers-namespace

pytest-helpers-namespace

JSON →
library2021.12.29pypypi✓ verified 85d ago

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.

pip install pytest-helpers-namespace
INSTALL
IMPORT
SIG · PYTEST-HELPERS-NAM
P
pytest-helpers-namespace
testingpythonv2021.12.29
Install
2.7s avg
Import
416ms
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2021.12.29 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.443s · 30.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.7s · import 0.389s · 31MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PACKAGE_ROOT
from pytest_helpers_namespace import PACKAGE_ROOT
import pytest
pathlib
from pytest_helpers_namespace import pathlib
import pytest
version
from pytest_helpers_namespace import version
import pytest

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'
Debug
Known issues
breakingStarting with version 2021.3.24, pytest-helpers-namespace requires pytest version 6.1.1 or newer. Older versions of the plugin may be incompatible with newer pytest versions, and upgrading the plugin will necessitate upgrading pytest.
fix
Ensure your pytest installation is `pytest>=6.1.1`. Run `pip install --upgrade pytest`.
affects: >=2021.3.24
breakingVersion 2021.3.24 introduced a switch to a 'src' layout. While this primarily affects packaging and internal structure, users who might have relied on specific internal import paths (though not recommended) could experience import errors.
fix
Stick to the public API (e.g., `pytest.helpers.register`). If you had custom import logic for internals, verify paths or adjust packaging.
affects: >=2021.3.24
gotchaUsing pytest fixtures directly as default arguments in functions registered with `@pytest.helpers.register` will pass the fixture function itself, not its resolved value. This typically leads to `TypeError: 'function' object is not subscriptable` when trying to access attributes or call the fixture within the helper.
fix
Pass the *resolved* fixture value from the test function as an explicit argument to your helper function, or make your helper a fixture if it needs direct fixture access.
affects: All versions
gotchaThe `pytest_plugins = ['helpers_namespace']` line in `conftest.py` is crucial for pytest to discover and load the plugin, making `pytest.helpers` available. Without it, or if there's an issue with automatic discovery (e.g., package not installed correctly), `pytest.helpers` will not exist.
fix
Always include `pytest_plugins = ['helpers_namespace']` in your root `conftest.py` to ensure the plugin is explicitly loaded.
affects: All versions
Upgrade
Version history
2021.12.29latest on PyPI · released Dec 29, 2021
Audit
Dependencies
pytestrequiredRequired by the plugin. Version 2021.3.24 and newer require pytest >= 6.1.1.
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
pytest-helpers-namespace — pip install pytest-helpers-namespace · libregistry