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!
Metadata
Release files for magic-patch 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| magic_patch-0.0.2.tar.gz | 3.2 kB | Without provenance | Details for magic_patch-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| magic_patch-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for magic_patch-0.0.2-py3-none-any.whl |
Total release size: 6.5 kB
Release files / magic_patch-0.0.2.tar.gz
| Download URL | magic_patch-0.0.2.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44343bc2afb17a9f67c30c2f1e0095871d31ef21a0ee72a28ca8df779641c1e4
|
|
BLAKE2b-256 checksum How to use checksums |
2c51897be9fd8a7b99c26e2eb7937a85e66473c81f5dcddf3b55d16c1b901a01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / magic_patch-0.0.2-py3-none-any.whl
| Download URL | magic_patch-0.0.2-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
390f0fb27a6e59863987e721cb223826db81601a419cc379626cc0997f3ed126
|
|
BLAKE2b-256 checksum How to use checksums |
ac92f05e1f664847c49f5864631e54b8be764c7a8e7b44638846de74fc2c3c70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for magic-patch 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.