Skip to main content

Stub packages, modules and attributes.

Project description

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

release lic ci coverage

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.6+

  • 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]',

        # Replace `dummy` with generated MagicMock.
        'django.dummy': '[mock]',

        # Replace entire `cv2` module.
        'cv2': '[mock]',

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

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-stub-1.0.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

pytest_stub-1.0.0-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest-stub-1.0.0.tar.gz.

File metadata

  • Download URL: pytest-stub-1.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for pytest-stub-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bbca1d48c468e6d8865172fd772b9f9abf6c3894cbd28bb8c6c9879850edb05a
MD5 fefe2663cb5fb9ee192ebbf2703c45b4
BLAKE2b-256 b704759811ad8a3b63b558bb863cdcadd4796e876212e7b55c3db8ca5aca0429

See more details on using hashes here.

File details

Details for the file pytest_stub-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_stub-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4490aec561f2f31e8dc201c303fdf766432fd95a5cbb9d1ccf3ea849cd31d86f
MD5 fbb09ea51f617230edbde88a1ed9fd36
BLAKE2b-256 37ea8f3b30d7667cbe959e09f48e11a3947770ab4ee4778ed11cb48fdba9dd8d

See more details on using hashes here.

Supported by

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