Metadata-Version: 2.2
Name: patch-import
Version: 1.0.0
Summary: Python unit testing utility. Patches imports
Author-email: Pavel Shmakov <shmakovpn@yandex.ru>
License: MIT License
        
        Copyright (c) 2018 Real Python
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/shmakovpn/patch-import
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: tomli; python_version < "3.11" and extra == "dev"
Requires-Dist: pip-tools; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: reverse-patch; extra == "dev"

# patch-import

![Tests](https://github.com/shmakovpn/patch-import/actions/workflows/python-package.yml/badge.svg)
[![codecov](https://codecov.io/github/shmakovpn/patch-import/graph/badge.svg?token=744XXMAKOZ)](https://codecov.io/github/shmakovpn/patch-import)
![Mypy](https://github.com/shmakovpn/patch-import/actions/workflows/mypy.yml/badge.svg)

Sometimes it is necessary to disable the real import of a Python module and replace the import result with a mock object.

Example:

```py
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'
```
