Skip to main content

Python SharedMock

Build Status Coverage Status Docs Status

A multiprocessing-friendly Python mock object

Getting started

The SharedMock object has an interface similar to Python’s own unittest.mock.Mock. The main difference is that the state of a SharedMock object is shared among subprocesses. This allows you to easily test interactions of subprocesses with your mock instance.

from sharedmock.mock import SharedMock

sharedmock = SharedMock()

subprocess = mp.Process(target=sharedmock,
                        args=('fancyArg',))
subprocess.start()
subprocess.join()
subprocess.terminate()

expected_calls = [call('fancyArg')]
sharedmock.assert_has_calls(expected_calls,
                            same_order=False)

If the SharedMock were to be replaced by a unittest.mock.Mock in the example above, the assertion would fail. The interaction with the unittest.mock.Mock object would not get propagated to your test code:

E               AssertionError: Calls not found.
E               Expected: [call('fancyArg')]
E               Actual: []

Source

The entire source code is available on GitHub.

Documentation

Documentation can be found on Read the Docs.

Release files for sharedmock 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sharedmock 0.1.0
File Size Uploaded
sharedmock-0.1.0.tar.gz 7.6 kB Details

Release files / sharedmock-0.1.0.tar.gz

Download URL sharedmock-0.1.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
807104fca48b7bc4cc4260cbf235e276948181ead15fc65353895d3a2a0becc0
BLAKE2b-256 checksum
How to use checksums
6618732b03cddc2ab9a7ce5b3493c63b9592c77cc738c48d468433a788107bb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.18

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page