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.6.post1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

pytest_mockito-0.0.6.post1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_mockito-0.0.6.post1.tar.gz.

File metadata

  • Download URL: pytest_mockito-0.0.6.post1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_mockito-0.0.6.post1.tar.gz
Algorithm Hash digest
SHA256 67e26a69942de4c50001268c779700f8d722384d20385313a88e81b6d23fb71c
MD5 4243a60245ed83519eeffee08fcf3473
BLAKE2b-256 d21356507ae9b513d4bac9ac5e412e7ff66d34827fc5c23e44fccde37a5c82ef

See more details on using hashes here.

File details

Details for the file pytest_mockito-0.0.6.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_mockito-0.0.6.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8384e1ac3e92828475fb6d24d6888e97acef52d9a77328d1333d48e9174ddbf
MD5 6fe89c26bd720ef4a5daf7556f9a15e0
BLAKE2b-256 c89a3bb38852013dbb5f03191f35f75823a38cc9e01d2a087c5dfe735dacae94

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