Skip to main content

Base fixtures for mockito

Project description

Convenience plugin on top of mockito.

https://travis-ci.org/kaste/pytest-mockito.svg?branch=master

Install

pip install pytest-mockito

After that the plugin is enabled by default.

Fixtures

The plugin provides fixtures for the main entrypoints of mockito which guarantee that you unstub() on teardown. Usage is very simple and straightforward:

def test_foo(when):
    when(os.path).exists('/foo').thenReturn(False)
    assert os.path.exists('/foo')  # sic!
    # will still unstub/unpatch bc pytest will run the teardown

For convenience verifyStubbedInvocationsAreUsed is called just before unstub. This should warn you when you setup stubs that you actually don’t use.

You can also use a marker. usefixtures here will ensure an unstub at the end of each test, but does not actually inject the fixture:

import pytest

@pytest.mark.usefixtures('unstub')
class TestDog:
    def test(self):
        ...

To mark all test cases at the module level:

pytestmark = pytest.mark.usefixtures('unstub')

All of the following fixtures just export the equivalent mockito function but unstub() on teardown. The exception here is expect which also calls verifyNoUnwantedInteractions():

when
when2
expect
patch
unstub
spy2

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-mockito-0.0.4.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file pytest-mockito-0.0.4.tar.gz.

File metadata

File hashes

Hashes for pytest-mockito-0.0.4.tar.gz
Algorithm Hash digest
SHA256 40d40cdf118127dcb1e3c9e838b0d1c11d5197a23beaf10b6e3f42f9b6cb68a9
MD5 00b3cfcce8ee36dce15e8bf9895e9e02
BLAKE2b-256 a4f8ae0035931c603e4ed5db496c13b12a995f327ee1d86d1b705eb3b6b9365b

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