Skip to content

Investigate how to run FastAPI Tests with TaskIQ integrated into the stack #73

@devraj

Description

@devraj

Describe the bug
FastAPI provides a nice way to test our API endpoints.

Upon integrating TaskIQ, the tests have stopped working and throw a taskiq.exceptions.SendTaskError exception. I am assuming this is because the way the tests are executed don't boot up the context that TaskIQ requires to communicate with the backend to queue the tasks.

The ticket is a reminder to investigate what needs to be changed for this to work with TaskIQ integrated.

To Reproduce
Steps to reproduce the behavior:

  • Bring the stack up
  • Run task dev:test

If you comment our the Task queue portion in the handlers then the tests succeed.

Expected behavior
All tests should pass

Screenshots

INFO     sqlalchemy.engine.Engine:base.py:1841 SELECT "user".email, "user".mobile_number, "user".password, "user".otp_secret, "user".verification_token, "user".verification_token_expiry, "user".first_name, "user".last_name, "user".is_admin, "user".verified, "user".id, "user".created_at, "user".updated_at, "user".deleted_at 
FROM "user" 
WHERE "user".id = $1::UUID
INFO     sqlalchemy.engine.Engine:base.py:1841 [generated in 0.00007s] (UUID('5092ced5-15a6-40f8-b933-1df44a76237c'),)
INFO     sqlalchemy.engine.Engine:base.py:2688 ROLLBACK
==================================================== short test summary info =====================================================
FAILED tests/test_auth.py::test_signup - taskiq.exceptions.SendTaskError
================================================== 1 failed, 5 passed in 0.74s ===================================================
task: Failed to run task "dev:test": exit status 1
➜  lab-python-server git:(main) ✗ task dev:test
task: [dev:test] docker compose exec api sh -c "pytest"

Additional context
See also Async tests for FastAPI.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions