-
Notifications
You must be signed in to change notification settings - Fork 28
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
Dependency overrides are ignored #189
Comments
I'll take a look |
Fixed in 3.15.5. Please, take a look. |
@zmievsa it does not seem to be working still after your fix. I can reproduce the problem with my test client fixture. I verified that my mock_valid_user dependency is never called and instead the original security_scheme dependency is, and I get HTTP401 still. @pytest.fixture
async def test_client():
"""
Create an instance of the client.
:return: yield HTTP client.
"""
# Mock the user context
app.dependency_overrides[security_scheme] = mock_valid_user
# Create the client
async with LifespanManager(app):
async with AsyncClient(
app=app, base_url="http://test", follow_redirects=True
) as ac:
yield ac |
Understood. My test was not sufficient, then -- it covered three use cases out of four. Sadly, you have the fourth. I understand the issue that occurs here but the fix is going to be a little more involved. I'll hopefully come back to you tomorrow with a fix for this use case. In fact, it might be so involved that I would recommend just using a regular monkeypatch mock right now. |
@gabloe Fixed the bug in its entirety. Should work in all cases now. Can I ask you to check again? Version 3.15.7 |
Sorry to say it is still not working with dependency overrides. Using the same code example in the bug description I get HTTP401 unauthorized using Cadwyn and success response using FastAPI. |
Can you provide the full example, i.e. a repository along with requirements.txt (or pyproject.toml)? My tests indicate that this problem should be impossible. I'll look at it right away. |
Describe the bug
I use dependency_overrides in my pytest config so that I can mock the security dependency and inject a mocked user into the request. This works with FastAPI but with Cadwyn it looks like dependency overrides are ignored, or at least does not work as expected.
To Reproduce
Steps to reproduce the behavior:
A simple example using fastapi-azure-oauth:
Expected behavior
I expect that the mocked user will be injected into the request and the route succeeds with a HTTP2XX. This works with FastAPI, but when I switch to Cadwyn I get HTTP401.
The text was updated successfully, but these errors were encountered: