Convenience plugin on top of mockito.
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
Metadata
Release files for pytest-mockito 0.0.6.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_mockito-0.0.6.post1.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_mockito-0.0.6.post1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.5 kB
Release files / pytest_mockito-0.0.6.post1.tar.gz
| Download URL | pytest_mockito-0.0.6.post1.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67e26a69942de4c50001268c779700f8d722384d20385313a88e81b6d23fb71c
|
|
BLAKE2b-256 checksum How to use checksums |
d21356507ae9b513d4bac9ac5e412e7ff66d34827fc5c23e44fccde37a5c82ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pytest_mockito-0.0.6.post1-py3-none-any.whl
| Download URL | pytest_mockito-0.0.6.post1-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b8384e1ac3e92828475fb6d24d6888e97acef52d9a77328d1333d48e9174ddbf
|
|
BLAKE2b-256 checksum How to use checksums |
c89a3bb38852013dbb5f03191f35f75823a38cc9e01d2a087c5dfe735dacae94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|