crewai-experiments
crewai-experiments copied to clipboard
feat: Set up complete Python testing infrastructure with Poetry
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.tomlwith 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.lockfor reproducible builds
Testing Setup
- Testing Framework: Added pytest with extensions:
pytest-covfor code coverage reportingpytest-mockfor 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 filesmock_env_vars: Mock environment variablesmock_config: Mock configuration dictionarymock_langchain_llm: Mock LangChain LLMmock_crewai_agent: Mock CrewAI Agentmock_crewai_task: Mock CrewAI Taskmock_reddit_client: Mock Reddit (PRAW) clientsample_newsletter_data: Sample data for testingcapture_logs: Log capture fixture
Commands
poetry run test- Run all tests with coveragepoetry run tests- Alternative command (both work)poetry run pytest- Direct pytest execution
Additional Configuration
- Updated
.gitignorewith testing artifacts and Poetry files - Added validation tests to ensure infrastructure works correctly
- Configured coverage to exclude test files from coverage calculation
Testing Instructions
-
Install Poetry if not already installed:
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install -
Run tests:
poetry run test # or poetry run tests -
View coverage report:
- Terminal: Coverage is shown after test run
- HTML: Open
htmlcov/index.htmlin a browser - XML: Available at
coverage.xmlfor 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
testandtestscommands are available as requested - The setup follows Python testing best practices and modern tooling standards