Skip to content

Comments

feat: Set up complete Python testing infrastructure with Poetry#11

Open
llbbl wants to merge 1 commit intomajacinka:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up complete Python testing infrastructure with Poetry#11
llbbl wants to merge 1 commit intomajacinka:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 16, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the Python newsletter automation project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration
  • Dependencies: Migrated existing dependencies (crewai, langchain, praw, etc.) to Poetry
  • Python Version: Set to Python 3.9+ for compatibility with all dependencies
  • Lock File: Generated poetry.lock for reproducible builds

Testing Setup

  • Testing Framework: Added pytest with extensions:
    • pytest-cov for code coverage reporting
    • pytest-mock for mocking utilities
  • Configuration: Comprehensive pytest configuration including:
    • Test discovery patterns
    • Coverage settings with 80% threshold
    • HTML and XML coverage reports
    • Custom test markers (unit, integration, slow)
    • Strict mode for better error reporting

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures and configuration
├── unit/                # Unit tests directory
│   └── __init__.py
├── integration/         # Integration tests directory
│   └── __init__.py
└── test_infrastructure_validation.py  # Validation tests

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_env_vars: Mock environment variables
  • mock_config: Mock configuration dictionary
  • mock_langchain_llm: Mock LangChain LLM
  • mock_crewai_agent: Mock CrewAI Agent
  • mock_crewai_task: Mock CrewAI Task
  • mock_reddit_client: Mock Reddit (PRAW) client
  • sample_newsletter_data: Sample data for testing
  • capture_logs: Log capture fixture

Commands

  • poetry run test - Run all tests with coverage
  • poetry run tests - Alternative command (both work)
  • poetry run pytest - Direct pytest execution

Additional Configuration

  • Updated .gitignore with testing artifacts and Poetry files
  • Added validation tests to ensure infrastructure works correctly
  • Configured coverage to exclude test files from coverage calculation

Testing Instructions

  1. Install Poetry if not already installed:

    curl -sSL https://install.python-poetry.org | python3 -
  2. Install dependencies:

    poetry install
  3. Run tests:

    poetry run test
    # or
    poetry run tests
  4. View coverage report:

    • Terminal: Coverage is shown after test run
    • HTML: Open htmlcov/index.html in a browser
    • XML: Available at coverage.xml for CI/CD integration

Notes

  • All validation tests pass successfully
  • The infrastructure is ready for developers to write actual unit and integration tests
  • Coverage threshold is set to 80% but currently excludes source files (only infrastructure is tested)
  • Both test and tests commands are available as requested
  • The setup follows Python testing best practices and modern tooling standards

- Configure Poetry as package manager with all project dependencies
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Create comprehensive pytest configuration with coverage thresholds
- Establish testing directory structure with unit/integration separation
- Add shared fixtures in conftest.py for common test patterns
- Configure test markers for categorizing tests (unit, integration, slow)
- Update .gitignore with testing and Poetry-related entries
- Add validation tests to verify infrastructure setup
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