Open SebaRossi94 opened 7 months ago
In case you did not find a solution yet.
The problem might be, that the override override_jwt_dependency
has one argument fake_jwt
. This should be the same as adding it this argument in the me
function, resulting in an expected query parameter fake_jwt
. (.../api/me?fake_jwt=<some value>
).
Using a function without any arguments as override however should work:
# conftest.py
...
@pytest.fixture()
def app_with_db_and_jwt(app_with_db):
def override_jwt_dependency():
return TokenData(id=1, email="jointhedarkside@empire.com")
app_with_db.dependency_overrides[validate_access_token] = override_jwt_dependency
yield app_with_db
app_with_db.dependency_overrides.pop(validate_access_token) # remove override
I managed to override my DB dependency for my testing in FastAPI but when I try to apply the same technique for overriding my JWT auth dependency I still get a 422 response with the following detail:
I followed all documentation and suggested posts on this topic of overriding dependencies for testing and still haven't found my issue. Does anyone know what's the problem here? Here are the involved codes:
conftest.py
test.py
schemas.py
router.py
dependencies.py