Skip to content

Docs: Depends import gotcha #8215

@Dilski

Description

@Dilski

What were you searching in the docs?

Absolutely loving that new Depends in the REST API handler, massive improvement to how we've done things.

Something we've noticed is when testing with dependency overrides, the imports for the dependency function have to match exactly between the test file and the handler file.

For example doing dependency overrides with get_config in a test with imports like this (despite it being the same actual function) means the override won't be applied and will instead resolve the actual get_config.

# in handler.py
from depends import get_config

# in test_handler.py
from my_app.api_handler.depends import get_config

what you need to do would be

# in handler.py
from depends import get_config

# in test_handler.py
from depends import get_config

This is a funky gotcha that's not immediately obvious or debuggable, so a note in the docs could be helpful.

Is this related to an existing documentation section?

https://docs.aws.amazon.com/powertools/python/latest/core/event_handler/api_gateway/#testing-with-dependency-overrides

How can we improve?

I think having a call-out about this gotcha could be helpful in the testing section.

Got a suggestion in mind?

When using dependency_overrides, the imported dependency reference in your test must exactly match the one used by the handler. (With sensible example, like what I've provided)

Acknowledgment

  • I understand the final update might be different from my proposed suggestion, or refused.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationtriagePending triage from maintainers

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions