Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 3, 2025

Add Python Testing Infrastructure

Summary

This PR adds a complete testing infrastructure to the Python project, providing developers with a ready-to-use testing environment for writing and running tests.

Changes Made

Package Management

  • Added Poetry configuration (pyproject.toml) with existing dependencies migrated from requirements.txt
  • Dependencies: streamlit, openai as production dependencies
  • Testing dependencies: pytest, pytest-cov, pytest-mock in test group

Testing Configuration

  • Comprehensive pytest configuration with test discovery patterns, coverage settings (30% threshold), and custom markers (unit, integration, slow)
  • Coverage reporting configured for HTML, XML, and terminal output formats
  • Strict pytest options enabled for better test reliability

Directory Structure

  • Organized test structure:
    • tests/ - Main test directory with __init__.py
    • tests/unit/ - Unit tests directory
    • tests/integration/ - Integration tests directory
    • tests/conftest.py - Shared fixtures and configuration

Testing Utilities

  • Comprehensive fixtures including:
    • temp_dir - Temporary directory for tests
    • mock_openai_api - Mock OpenAI API responses
    • mock_streamlit - Mock Streamlit components
    • mock_env_vars - Mock environment variables
    • sample_email_data - Test data fixtures
  • Validation tests to ensure the infrastructure works correctly

Development Setup

  • Updated .gitignore with testing-related entries, build artifacts, and Claude settings
  • Poetry lock file properly configured (not ignored in git)
  • Coverage configuration targeting the main streamlit_app.py file

Running Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest

Run Tests with Verbose Output

poetry run pytest -v

Run Tests by Marker

poetry run pytest -m unit        # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m slow        # Slow tests only

Generate Coverage Report

poetry run pytest --cov-report=html
# View report: open htmlcov/index.html

Testing Infrastructure Features

  • Poetry package management with proper dependency isolation
  • Pytest framework with comprehensive configuration
  • Coverage reporting with HTML/XML/terminal outputs
  • Custom test markers for test categorization
  • Shared fixtures for common testing scenarios
  • Mock utilities for external dependencies (OpenAI, Streamlit)
  • Organized directory structure for scalable test organization
  • Validation tests to verify infrastructure functionality

Notes

  • Coverage threshold: Set to 30% for initial setup (can be increased as tests are added)
  • Test discovery: Configured to find test_*.py and *_test.py files
  • Dependencies: All testing dependencies are isolated in the test group
  • Poetry scripts: Use poetry run pytest directly for running tests

The testing infrastructure is now ready for developers to start writing unit and integration tests immediately.

🤖 Generated with Claude Code

Set up complete testing environment with Poetry package management, pytest framework, coverage reporting, and organized test structure. Infrastructure includes shared fixtures, validation tests, and proper configuration for development workflows.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant