Skip to main content

A multiprocessing-friendly Python mock object

Project description

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.

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

sharedmock-0.1.0.tar.gz (7.6 kB view hashes)

Uploaded Source

Supported by

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