Skip to main content

The magic_patch is a simple library that provides the ability to patch an object in different scopes at once. Now you can patch objects easily like magic.

Project description

The magic_patch is a simple library that provides the ability to patch an object in different scopes at once. Now you can patch objects easily like magic.

  • Example 1 * A project contains a few modules that imports datetime library
# module 1
from datetime import datetime

...
# module 2
from datetime import datetime

...

Using magic_patch you don't need to patch each module manually

# test
from unittest.mock import Mock
from magic_patch import magic_patch

from datetime import datetime  # import target object
from ... import start_module  # necessary to run imports 

datetime_mock = Mock()

with magic_patch(start_module, datetime, datetime_mock):
    # all done! - all modules patched!!!
    ...
  • Example 2 * A project contains a few modules that import the datetime class from datatime library There are different names for the target object. The magic_patch provides the ability to examine all available variables in each module
# module 1
from datetime import datetime

...
# module 2
from datetime import datetime as new_name_datetime

...

Just set up the option search_by_all_names=True and magic_patch finds your target with other names

# test
from unittest.mock import Mock
from magic_patch import magic_patch

from datetime import datetime  # import target object
from ... import start_module  # necessary to run imports 

datetime_mock = Mock()
with magic_patch(start_module, datetime, datetime_mock, search_by_all_names=True):
    # all done! - all modules patched!!!
    ...

Happy magic patching!

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

magic_patch-0.0.2.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

magic_patch-0.0.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file magic_patch-0.0.2.tar.gz.

File metadata

  • Download URL: magic_patch-0.0.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for magic_patch-0.0.2.tar.gz
Algorithm Hash digest
SHA256 44343bc2afb17a9f67c30c2f1e0095871d31ef21a0ee72a28ca8df779641c1e4
MD5 5a3538de59a9f414ef91cc391e0b3978
BLAKE2b-256 2c51897be9fd8a7b99c26e2eb7937a85e66473c81f5dcddf3b55d16c1b901a01

See more details on using hashes here.

File details

Details for the file magic_patch-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: magic_patch-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for magic_patch-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 390f0fb27a6e59863987e721cb223826db81601a419cc379626cc0997f3ed126
MD5 a89df04d797a57ec47f646e692212c2c
BLAKE2b-256 ac92f05e1f664847c49f5864631e54b8be764c7a8e7b44638846de74fc2c3c70

See more details on using hashes here.

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