This plugin does not provide any helpers to pytest, it does, however,
provide a helpers namespace in pytest which enables you to register helper
functions in your conftest.py
to be used within your tests without having
to import them.
- Provides a
helpers
pytest namespace which can be used to register helper functions without requiring you to import them on your actual tests to use them.
- None!
You can install "pytest-helpers-namespace" via pip from PyPI:
$ pip install pytest-helpers-namespace
Consider the following conftest.py
file:
import pytest
@pytest.helpers.register
def foo(bar):
'''
this dumb helper function will just return what you pass to it
'''
return bar
And now consider the following test case:
def test_helper_namespace():
assert pytest.helpers.foo(True) is True
Pretty simple right?!
You can even nest namespaces. Consider the following conftest.py
file:
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
And now consider the following test case:
def test_helper_namespace():
assert pytest.helpers.can.haz.foo(True) is True
You can even pass a name to the register function and that will be the helper function name.
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the Apache Software License 2.0 license, "pytest-helpers-namespace" is free and open source software.
If you encounter any problems, please file an issue along with a detailed description.
- Switched project to a
src
layout. - Switched project to a declarative setuptools approach
- Added support to check if a helper has been registered
- Patch PyTest before any
conftest.py
file is processed.
- Support PyTest >= 4.1
- No changes were made besides locking to PyTest < 4.0
- No changes were made besides locking to PyTest < 4.1
- Allow passing a string to the register function which will be the helper name
- Allow a registered function to contibue to behave as a regular function. #4.
- Use a wrapper class instead of adding an attribute to a function.
- Provide proper errors when helper functions or namespaces are being overridden. #1
- First working release
This Pytest plugin was generated with Cookiecutter along with @hackebrot's Cookiecutter-pytest-plugin template.