Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support patching of injection registry for testing #174

Open
timsavage opened this issue Jul 20, 2022 · 0 comments
Open

Support patching of injection registry for testing #174

timsavage opened this issue Jul 20, 2022 · 0 comments
Assignees
Labels
📖 docs required Documentation is required for this Pull Request to be accepted 💡 enhancement This issue/pr has been reviewed and accepted as an enhancement

Comments

@timsavage
Copy link
Collaborator

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()
    ]
@timsavage timsavage added 💡 enhancement This issue/pr has been reviewed and accepted as an enhancement 📖 docs required Documentation is required for this Pull Request to be accepted labels Jul 20, 2022
@timsavage timsavage self-assigned this Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📖 docs required Documentation is required for this Pull Request to be accepted 💡 enhancement This issue/pr has been reviewed and accepted as an enhancement
Projects
None yet
Development

No branches or pull requests

1 participant