Support patching of injection registry for testing
Opened this issue · 0 comments
timsavage commented
Similar to how settings can be patched for testing, the injection registry should also allow Mocks to be injected for test purposes.
With an interface like:
from unittest.mock import Mock, call
from pyapp import injection
def test_function_with_injected_type():
with injection.default_registry.modify() as patch:
mocked_type = Mock(spec_set=MyType)
# With a helper factory generator
patch.mock_factory(MyType, mocked_type)
# With a direct inserted item
patch[MyType] = Mock(return_value=mocked_type)
function_with_injected_type()
assert mocked_type.method.mock_calls == [
call()
]