Skip to content

Write unit tests with pytest and TestClient #9

Description

@Navashub

Description

The project has no automated tests. Add a pytest test suite covering the core CRUD flows.

What to do

  • Add pip install pytest httpx to dependencies
  • Create a tests/ folder with __init__.py and test_tasks.py, test_users.py
  • Use FastAPI's TestClient with an in-memory SQLite database (not tasks.db)
  • Write tests for at minimum:
    • Create a user → assert 200, assert name in response
    • Create a task for that user → assert 200, assert completed is False
    • Get all tasks → assert list contains the created task
    • Update task to completed → assert completed is True
    • Delete the task → assert 200, assert task no longer returned

Acceptance Criteria

  • pytest runs and all tests pass
  • Tests use a separate test database, not the development tasks.db
  • No test leaves data behind (use TestClient with a fresh DB per session)

Hints

Difficulty

🟡 Intermediate

Metadata

Metadata

Assignees

No one assigned

    Labels

    intermediateRequires some FastAPI experiencetestingPytest, TestClient

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions