sharedmock


Namesharedmock JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/elritsch/python-sharedmock
SummaryA multiprocessing-friendly Python mock object
upload_time2024-02-07 02:51:08
maintainer
docs_urlNone
authorElmar Ritsch
requires_python
licenseApache v2.0
keywords testing multiprocessing development
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            Python ``SharedMock``
=====================

|Build Status| |Coverage Status| |Docs Status|

.. |Build Status| image:: https://travis-ci.org/elritsch/python-sharedmock.svg?branch=master
   :target: https://travis-ci.org/elritsch/python-sharedmock
.. |Coverage Status| image:: https://coveralls.io/repos/github/elritsch/python-sharedmock/badge.svg?branch=master
   :target: https://coveralls.io/github/elritsch/python-sharedmock?branch=master
.. |Docs Status| image:: https://readthedocs.org/projects/python-sharedmock/badge/?version=latest
   :target: http://python-sharedmock.readthedocs.io/en/latest/?badge=latest

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.

.. code:: python

    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:

.. code:: python

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

Source
------

The entire source code is available on `GitHub`_.

.. _GitHub: https://github.com/elritsch/python-sharedmock

Documentation
-------------

Documentation can be found on `Read the Docs`_.

.. _Read the Docs: https://python-sharedmock.readthedocs.io

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/elritsch/python-sharedmock",
    "name": "sharedmock",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "testing multiprocessing development",
    "author": "Elmar Ritsch",
    "author_email": "elmar.ritsch@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/66/18/732b03cddc2ab9a7ce5b3493c63b9592c77cc738c48d468433a788107bb4/sharedmock-0.1.0.tar.gz",
    "platform": null,
    "description": "Python ``SharedMock``\n=====================\n\n|Build Status| |Coverage Status| |Docs Status|\n\n.. |Build Status| image:: https://travis-ci.org/elritsch/python-sharedmock.svg?branch=master\n   :target: https://travis-ci.org/elritsch/python-sharedmock\n.. |Coverage Status| image:: https://coveralls.io/repos/github/elritsch/python-sharedmock/badge.svg?branch=master\n   :target: https://coveralls.io/github/elritsch/python-sharedmock?branch=master\n.. |Docs Status| image:: https://readthedocs.org/projects/python-sharedmock/badge/?version=latest\n   :target: http://python-sharedmock.readthedocs.io/en/latest/?badge=latest\n\nA multiprocessing-friendly Python mock object\n\nGetting started\n---------------\n\nThe ``SharedMock`` object has an interface similar to Python\u2019s own\n``unittest.mock.Mock``. The main difference is that the state of a\n``SharedMock`` object is shared among subprocesses. This allows you to\neasily test interactions of subprocesses with your mock instance.\n\n.. code:: python\n\n    from sharedmock.mock import SharedMock\n\n    sharedmock = SharedMock()\n\n    subprocess = mp.Process(target=sharedmock,\n                            args=('fancyArg',))\n    subprocess.start()\n    subprocess.join()\n    subprocess.terminate()\n\n    expected_calls = [call('fancyArg')]\n    sharedmock.assert_has_calls(expected_calls,\n                                same_order=False)\n\nIf the ``SharedMock`` were to be replaced by a ``unittest.mock.Mock`` in\nthe example above, the assertion would fail. The interaction with the\n``unittest.mock.Mock`` object would not get propagated to your test\ncode:\n\n.. code:: python\n\n    E               AssertionError: Calls not found.\n    E               Expected: [call('fancyArg')]\n    E               Actual: []\n\nSource\n------\n\nThe entire source code is available on `GitHub`_.\n\n.. _GitHub: https://github.com/elritsch/python-sharedmock\n\nDocumentation\n-------------\n\nDocumentation can be found on `Read the Docs`_.\n\n.. _Read the Docs: https://python-sharedmock.readthedocs.io\n",
    "bugtrack_url": null,
    "license": "Apache v2.0",
    "summary": "A multiprocessing-friendly Python mock object",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/elritsch/python-sharedmock"
    },
    "split_keywords": [
        "testing",
        "multiprocessing",
        "development"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6618732b03cddc2ab9a7ce5b3493c63b9592c77cc738c48d468433a788107bb4",
                "md5": "1b4148afddd1e2699397f9cdfc85ad0a",
                "sha256": "807104fca48b7bc4cc4260cbf235e276948181ead15fc65353895d3a2a0becc0"
            },
            "downloads": -1,
            "filename": "sharedmock-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1b4148afddd1e2699397f9cdfc85ad0a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7558,
            "upload_time": "2024-02-07T02:51:08",
            "upload_time_iso_8601": "2024-02-07T02:51:08.709062Z",
            "url": "https://files.pythonhosted.org/packages/66/18/732b03cddc2ab9a7ce5b3493c63b9592c77cc738c48d468433a788107bb4/sharedmock-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-07 02:51:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "elritsch",
    "github_project": "python-sharedmock",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "requirements": [],
    "lcname": "sharedmock"
}
        
Elapsed time: 0.21821s