Open
Description
When I try to create a container, it seems there are no checks in place which prevent me from passing in an instance of an incorrect type.
I declared a provided_type
field for my custom factory class as described.
Or, is the error rather on my side and I am using the library in an incorrect way?
I expect the test test_incorrect_type_instanciation
to pass. Instead, no exception is raised:
def test_incorrect_type_instanciation():
service = object()
> with pytest.raises(Exception):
E Failed: DID NOT RAISE <class 'Exception'>
container_types.py:30: Failed
Click to toggle
import pytest
from dependency_injector import containers, providers
class BaseService:
...
class ServiceProvider(providers.Factory):
provided_type = BaseService
class Application(containers.DeclarativeContainer):
service = ServiceProvider(BaseService)
def test_ok():
c = Application()
assert isinstance(c.service(), BaseService)
def test_incorrect_type_declaration():
with pytest.raises(Exception):
class Container(containers.DeclarativeContainer):
service = ServiceProvider(object)
def test_incorrect_type_instanciation():
service = object()
with pytest.raises(Exception):
c = Application(service=service)
c.service()