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
Release history Release notifications | RSS feed
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.1.tar.gz
(3.1 kB
view details)
Built Distribution
File details
Details for the file magic_patch-0.0.1.tar.gz
.
File metadata
- Download URL: magic_patch-0.0.1.tar.gz
- Upload date:
- Size: 3.1 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc296121b9fecf9fafa2f3fcb413acadbdedaa68609ef12fc28a1c63bf7eb8b1 |
|
MD5 | b00372d536373e0abb237d20ec309301 |
|
BLAKE2b-256 | 2be7d129ccf00780a9560db53e68db506a86bb72fd80d790c391e6f1ed9ea4ad |
File details
Details for the file magic_patch-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: magic_patch-0.0.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d120c683f44bc78212d2fa886f11fe3f814eca9cc516296f2fd12742880ee1d |
|
MD5 | f79071fd0da6adb3739b7fcc555c5bd2 |
|
BLAKE2b-256 | d4e2128bcbb7e954bfb76d21ca1587ece246553e7cd1c5b7073d5426899f1189 |