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

First-class support for testing #106

Open
roo-oliv opened this issue Aug 16, 2021 · 2 comments
Open

First-class support for testing #106

roo-oliv opened this issue Aug 16, 2021 · 2 comments

Comments

@roo-oliv
Copy link
Owner

Supplying fake/mocked/stubbed injectables should be really easy.

An example feature would be to introduce a helper fixture for pytest:

@pytest.fixture()
def given_injectable():
    originals: Dict[Union[type, str], Tuple[Set[Injectable], bool]] = {}

    def register(constructor: callable, klass=None, qualifier=None, propagate=False):
        if not klass and not qualifier:
            raise ValueError("params 'klass' and 'qualifier' cannot be both None")
        if propagate and not klass:
            raise ValueError("param 'klass' must be set when 'propagate' is True")
        for dependency in klass, qualifier:
            if not dependency or dependency in originals:
                continue
            originals[dependency] = clear_injectables(dependency), propagate
        register_injectables(
            {Injectable(constructor)}, klass, qualifier, propagate=propagate
        )

    yield register

    for dependency, (injectables, propagate) in originals.items():
        clear_injectables(dependency)
        if isinstance(dependency, str):
            register_injectables(injectables, qualifier=dependency, propagate=propagate)
        else:
            register_injectables(injectables, klass=dependency, propagate=propagate)
@javiermrzfever
Copy link

Hi! Any updates on this? I've been searching for a nice python DI package and this is by bar the most friendly and easy to use. I see a lot of intention on adding new features and maintaining it, but I don't see any new release since 2021. What is the state of the library?

Thanks!

@roo-oliv
Copy link
Owner Author

roo-oliv commented Apr 2, 2024

Hi @javiermrzfever, thanks for reaching out! ❤️

I've been working to make injectable compatible with newer Python versions since 2023 but I've found it to be quite more work than I expected. So this is why it has been a while since the latest release. Good news is that I plan to release a new version by May'24 🎉

@roo-oliv roo-oliv moved this to To do in dev board Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To do
Development

No branches or pull requests

2 participants