This proposal adds comprehensive pytest testing for all existing features: - Unit tests for validation logic - Integration tests for database operations and GraphQL resolvers - E2E tests for complete API flows - MCP server tests for all 6 tools 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3.1 KiB
3.1 KiB
Add Pytest Tests Proposal
Why
The project currently has no automated tests despite having pytest and pytest-asyncio configured in pyproject.toml. This creates several risks:
- Regression risk: Changes to existing features (member CRUD operations, GraphQL resolvers, MCP tools, validation logic) may break functionality without detection
- Confidence: Developers and AI assistants lack confidence when refactoring or adding features
- Documentation gap: Tests serve as executable documentation of expected behavior
- Quality assurance: No automated verification of business rules (validation, sorting, error handling)
Testing is critical for:
- Member CRUD operations (create, read, update, delete)
- GraphQL API (queries, mutations, introspection)
- MCP server tools (6 tools connecting to GraphQL API)
- Validation logic (email, phone, firstName)
- Database operations (async SQLAlchemy patterns)
What
Implement comprehensive pytest test suite covering existing features:
Test Infrastructure
- Create
tests/directory with proper structure (unit, integration, e2e, mcp) - Configure pytest fixtures for database setup (in-memory SQLite)
- Configure async test support (pytest-asyncio already in dependencies)
- Add conftest.py with shared fixtures
Test Coverage
-
Unit Tests (
tests/unit/)- Validation logic (email, phone, firstName)
- Utility functions
-
Integration Tests (
tests/integration/)- Database operations with Member model
- GraphQL resolvers (Query, Mutation)
- Error handling (MemberNotFoundError, ValidationError)
-
E2E Tests (
tests/e2e/)- Complete GraphQL query flows
- Complete GraphQL mutation flows
- GraphQL introspection queries
-
MCP Tests (
tests/mcp/)- MCP server tool definitions
- MCP tool execution (list_members, get_member, create_member, update_member)
- General GraphQL tools (get_graphql_schema, execute_graphql_query)
Documentation
- Update README.md with testing instructions
- Add "Running Tests" section
- Add "Test Coverage" section
- Document test organization and conventions
Impact
Breaking Changes
None - purely additive.
New Dependencies
None - pytest and pytest-asyncio already in dev dependencies.
Migration
No migration needed.
Alternatives Considered
-
unittest instead of pytest
- Rejected: pytest is already configured and provides better async support, fixtures, and test discovery
-
Test only critical paths
- Rejected: Comprehensive testing provides better confidence and documentation
-
Skip MCP tests
- Rejected: MCP server is a core component and needs testing
Success Criteria
- Test suite runs with
uv run pytest - All existing features have test coverage
- Tests are organized logically (unit, integration, e2e, mcp)
- Tests use proper fixtures for database setup
- README.md documents how to run tests
- No changes to production code (except minor fixes if bugs are found)
Related Changes
None - this is the first testing implementation.
Open Questions
None - the implementation is straightforward.