Skip to content

Commit 702df96

Browse files
committed
Fix wiring module loader uninstallation issue
1 parent a7de2dc commit 702df96

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

docs/main/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Development version
1212
- Implement providers' lazy initialization.
1313
- Improve providers' copying.
1414
- Improve typing in wiring module.
15+
- Fix wiring module loader uninstallation issue.
1516

1617
4.30.0
1718
------

src/dependency_injector/wiring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ def wire_module(self, module):
860860

861861
@property
862862
def installed(self):
863-
return self._path_hook is not None
863+
return self._path_hook in sys.path_hooks
864864

865865
def install(self):
866866
if self.installed:

tests/unit/wiring/test_wiring_string_ids_py36.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import contextlib
12
from decimal import Decimal
3+
import importlib
24
import unittest
35

46
from dependency_injector.wiring import (
57
wire,
68
Provide,
79
Provider,
810
Closing,
11+
register_loader_containers,
12+
unregister_loader_containers,
913
)
1014
from dependency_injector import containers, providers, errors
1115

@@ -409,27 +413,27 @@ def test_async_injections_with_closing(self):
409413
self.assertEqual(asyncinjections.resource2.shutdown_counter, 2)
410414

411415

412-
# class AutoLoaderTest(unittest.TestCase):
413-
#
414-
# container: Container
415-
#
416-
# def setUp(self) -> None:
417-
# self.container = Container(config={'a': {'b': {'c': 10}}})
418-
# importlib.reload(module)
419-
#
420-
# def tearDown(self) -> None:
421-
# with contextlib.suppress(ValueError):
422-
# unregister_loader_containers(self.container)
423-
#
424-
# self.container.unwire()
425-
#
426-
# @classmethod
427-
# def tearDownClass(cls) -> None:
428-
# importlib.reload(module)
429-
#
430-
# def test_register_container(self):
431-
# register_loader_containers(self.container)
432-
# importlib.reload(module)
433-
#
434-
# service = module.test_function()
435-
# self.assertIsInstance(service, Service)
416+
class AutoLoaderTest(unittest.TestCase):
417+
418+
container: Container
419+
420+
def setUp(self) -> None:
421+
self.container = Container(config={'a': {'b': {'c': 10}}})
422+
importlib.reload(module)
423+
424+
def tearDown(self) -> None:
425+
with contextlib.suppress(ValueError):
426+
unregister_loader_containers(self.container)
427+
428+
self.container.unwire()
429+
430+
@classmethod
431+
def tearDownClass(cls) -> None:
432+
importlib.reload(module)
433+
434+
def test_register_container(self):
435+
register_loader_containers(self.container)
436+
importlib.reload(module)
437+
438+
service = module.test_function()
439+
self.assertIsInstance(service, Service)

0 commit comments

Comments
 (0)