patch-import
Sometimes it is necessary to disable the real import of a Python module and replace the import result with a mock object.
Example:
import pytest
from patch_import import patch_import
@pytest.fixture
def aiohttp__import_fixture():
with patch_import('aiohttp') as mocked_aiohttp:
mocked_aiohttp.__version__ = '3.3.3'
yield mocked_aiohttp
class TestPatchImport:
def test_patch_import(self, aiohttp__import_fixture):
"""An example test with patch_import"""
# patch_import__fixtures.py imports aiohttp which does not present in a project environment
# thus, we need to disable real import and replace aiohttp for a mock object
from patch_import.patch_import__fixtures import MyClass # please look at src/patch_import/patch_import__fixtures.py
assert MyClass.version() == '3.3.3'
Metadata
Release files for patch-import 1.0.0
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 |
|---|---|---|---|---|
| patch_import-1.0.0.tar.gz | 3.4 kB | Without provenance | Details for patch_import-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| patch_import-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for patch_import-1.0.0-py3-none-any.whl |
Total release size: 7.9 kB
Release files / patch_import-1.0.0.tar.gz
| Download URL | patch_import-1.0.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9aaa16c607718cf1377ff3e23c4af282b09b05136ee3d47ae0e7a056b5316a12
|
|
BLAKE2b-256 checksum How to use checksums |
0e5e3d8d88a16ae971f4d6ab547ff4997f25feedd1429d17708903e3c86f7e3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Release files / patch_import-1.0.0-py3-none-any.whl
| Download URL | patch_import-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae2ed7770946254a8df77052f68033286c0360103363293e02d5f57d296b227e
|
|
BLAKE2b-256 checksum How to use checksums |
3513e9e7aedfd0d3219a3b3fca197a5a596cdb9cd3d472fd2e87bd08198702d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Security for patch-import 1.0.0
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.