for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import pytest
from lagom import Container
from lagom.exceptions import DuplicateDefinition
class InitialDep:
pass
class SomeMockForTesting(InitialDep):
class SomeMockThatDoesntEventExtend:
def test_deps_can_be_overridden_by_a_child_class(container: Container):
container.define(InitialDep, lambda: SomeMockForTesting())
resolved = container.resolve(InitialDep)
assert type(resolved) == SomeMockForTesting
def test_deps_can_be_overridden_by_anything(container: Container):
container.define(InitialDep, lambda: SomeMockThatDoesntEventExtend()) # type: ignore
assert type(resolved) == SomeMockThatDoesntEventExtend
def test_explicit_definitions_can_only_be_made_once(container: Container):
with pytest.raises(DuplicateDefinition):
container.define(
InitialDep, lambda: SomeMockThatDoesntEventExtend() # type: ignore
)