mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Update wiring to support modules provided as packages
This commit is contained in:
parent
b4ddf61939
commit
7bdcc33eda
|
@ -552,6 +552,8 @@ def _unbind_injections(fn: Callable[..., Any]) -> None:
|
||||||
|
|
||||||
def _fetch_modules(package):
|
def _fetch_modules(package):
|
||||||
modules = [package]
|
modules = [package]
|
||||||
|
if not hasattr(package, '__path__') or not hasattr(package, '__name__'):
|
||||||
|
return modules
|
||||||
for module_info in pkgutil.walk_packages(
|
for module_info in pkgutil.walk_packages(
|
||||||
path=package.__path__,
|
path=package.__path__,
|
||||||
prefix=package.__name__ + '.',
|
prefix=package.__name__ + '.',
|
||||||
|
|
|
@ -310,6 +310,18 @@ class WiringTest(unittest.TestCase):
|
||||||
self.assertIsInstance(service, Service)
|
self.assertIsInstance(service, Service)
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleAsPackagingTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.container = Container(config={'a': {'b': {'c': 10}}})
|
||||||
|
self.addCleanup(self.container.unwire)
|
||||||
|
|
||||||
|
def test_module_as_package_wiring(self):
|
||||||
|
# See: https://github.com/ets-labs/python-dependency-injector/issues/481
|
||||||
|
self.container.wire(packages=[module])
|
||||||
|
self.assertIsInstance(module.service, Service)
|
||||||
|
|
||||||
|
|
||||||
class WiringAndQueue(unittest.TestCase):
|
class WiringAndQueue(unittest.TestCase):
|
||||||
|
|
||||||
def test_wire_queue(self) -> None:
|
def test_wire_queue(self) -> None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user