Skip to main content

Pytest Helpers Namespace Plugin

Project description

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

Pytest Helpers Namespace

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.

Features

  • 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.

Requirements

  • None!

Installation

You can install “pytest-helpers-namespace” via pip from PyPI:

$ pip install pytest-helpers-namespace

Usage

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.

Contributing

Contributions are very welcome. Tests can be run with nox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the Apache Software License 2.0 license, “pytest-helpers-namespace” is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Changelog

v2021.3.24

  • Switched project to a src layout.

  • Switched project to a declarative setuptools approach

  • Added support to check if a helper has been registered

  • Pytest >= 6.1.1 is now required

v2019.1.8

  • Patch PyTest before any conftest.py file is processed.

v2019.1.7

  • Support PyTest >= 4.1

v2019.1.6.post1

  • No changes were made besides locking to PyTest < 4.0

v2019.1.6

  • No changes were made besides locking to PyTest < 4.1

v2017.11.11

  • Allow passing a string to the register function which will be the helper name

v2016.7.10

  • Allow a registered function to contibue to behave as a regular function. #4.

v2016.4.15

  • Hide the FuncWrapper traceback in pytest failures. #3. Thanks Logan Glickfield(@lsglick)

v2016.4.5

  • Use a wrapper class instead of adding an attribute to a function.

v2016.4.3

  • Provide proper errors when helper functions or namespaces are being overridden. #1

v2016.3.2

  • First working release


This Pytest plugin was generated with Cookiecutter along with @hackebrot’s Cookiecutter-pytest-plugin template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-helpers-namespace-2021.4.29.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_helpers_namespace-2021.4.29-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest-helpers-namespace-2021.4.29.tar.gz.

File metadata

  • Download URL: pytest-helpers-namespace-2021.4.29.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.7

File hashes

Hashes for pytest-helpers-namespace-2021.4.29.tar.gz
Algorithm Hash digest
SHA256 183524e3db4e2a1fea92e0ca3662a624ba44c9f3568da15679d7535ba6838a6a
MD5 ac3eb6f6ddac80122ea5ba0d8a19411d
BLAKE2b-256 1a5a729a5778652b50bead23d5dce704ab98edad76d8bd801a1cf8c040aada0e

See more details on using hashes here.

File details

Details for the file pytest_helpers_namespace-2021.4.29-py3-none-any.whl.

File metadata

  • Download URL: pytest_helpers_namespace-2021.4.29-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.7

File hashes

Hashes for pytest_helpers_namespace-2021.4.29-py3-none-any.whl
Algorithm Hash digest
SHA256 2baa25df6f816304ea31986c18b0db55af17aef26cf5619d235429f08d8fa28c
MD5 7c609230896347ab662665a99b3d1cf0
BLAKE2b-256 2521259231fef189d28950e946947303874d9312c9d1a2ec791fc5e6b3cae4ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page