Skip to main content

A subclass of MagicMock that copies the arguments

Project description

travis coveralls pypi pyversions womm

MagicMock has problems when used on a function with mutable arguments. This is called out in the documentation:

Another situation is rare, but can bite you, is when your mock is called with mutable arguments. call_args and call_args_list store references to the arguments. If the arguments are mutated by the code under test then you can no longer make assertions about what the values were when the mock was called.

They then go on to propose a workaround, using side_effect, but it’s not very likable. There is also an elegant recipe offered which copies arguments at call-time. It’s simply a subclass of MagicMock which copies the arguments, instead of storing references. I’m not sure why the recipe wasn’t included directly in mock, so here it is as a third-party package.

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

copyingmock-0.2.tar.gz (2.0 kB view details)

Uploaded Source

Built Distribution

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

copyingmock-0.2-py2.py3-none-any.whl (3.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file copyingmock-0.2.tar.gz.

File metadata

  • Download URL: copyingmock-0.2.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for copyingmock-0.2.tar.gz
Algorithm Hash digest
SHA256 fa4c8aad336f6e74f7632f40ff5a271130be5def44ab3177af4578c4d4a66093
MD5 9aa6ba13542d25e527fe358d53cdaf3b
BLAKE2b-256 e74b857c745721ed3d5dc33c426d6e31aaff13a5cd5caaf444117139b2d9936f

See more details on using hashes here.

File details

Details for the file copyingmock-0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for copyingmock-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b8496586ab6f91af8d751ffd28c34a8b7ebe8058c4113d74d6521c6d35ec311f
MD5 497a0aaeb057481e16d6fae6ea281932
BLAKE2b-256 5e8e3b2f4e29f918759216f1d6c3b42e8b128f3b01d492046bcf45eb4b907e17

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