2020-08-14 23:27:17 +03:00
|
|
|
"""Declarative container provider override example."""
|
|
|
|
|
|
|
|
import sqlite3
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
2021-09-30 22:16:17 +03:00
|
|
|
database = providers.Singleton(sqlite3.connect, ":memory:")
|
2020-08-14 23:27:17 +03:00
|
|
|
|
|
|
|
|
2021-09-30 22:16:17 +03:00
|
|
|
if __name__ == "__main__":
|
2020-08-16 05:09:41 +03:00
|
|
|
container = Container(database=mock.Mock(sqlite3.Connection))
|
2020-08-14 23:27:17 +03:00
|
|
|
|
2020-08-16 05:09:41 +03:00
|
|
|
database = container.database()
|
|
|
|
assert isinstance(database, mock.Mock)
|