Stub packages, modules and attributes.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
pytest_stub Release v0.1.0 Dec 28, 2018
tests Start here. Dec 27, 2018
.coveragerc Coverage config updated. Dec 27, 2018
.gitignore Start here. Dec 27, 2018
.landscape.yaml Start here. Dec 27, 2018
.travis.yml Dropped QA for Python 3.4. Jan 17, 2019
AUTHORS Start here. Dec 27, 2018
CHANGELOG Dropped QA for Python 3.4. Jan 17, 2019
CONTRIBUTING Start here. Dec 27, 2018
INSTALL Start here. Dec 27, 2018
LICENSE Year updated. Jan 17, 2019
MANIFEST.in Start here. Dec 27, 2018
README.rst Readme updated. Jan 17, 2019
setup.cfg Start here. Dec 27, 2018
setup.py Dropped QA for Python 3.4. Jan 17, 2019
tox.ini Dropped QA for Python 3.4. Jan 17, 2019

README.rst

pytest-stub

https://github.com/idlesign/pytest-stub

release lic ci coverage health

Description

Stub packages, modules and attributes.

This pytest plugin allows you to replace dependencies with stubs.

It can be useful if you want to test some code using a dependency without actually having this dependency, for example if you're testing your library, which uses some parts of another library.

Requirements

  • Python 3.5+
  • pytest >= 2.9.0

How to use

Use stub fixture in your test functions, like this:

def test_django_related(stub):

    stub.apply({
        # Replace `call_command` with a generated function.
        'django.core.management.call_command': '[func]',

        # Replace `BaseCommand` with a generated class.
        'django.core.management.base.BaseCommand': '[cls]',

        # Stub multiple attributes in the same module with custom objects.
        'django.conf': {
            'settings': object(),
            'some': True,
        },

    })

You can stub dependencies either with your own custom objects or you may instruct pytest-stub to generate functions or classes for you.