stocktalk
stocktalk copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the stocktalk Python project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith Poetry configuration - Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry - Development Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies
Testing Configuration
-
Pytest Settings: Configured pytest with:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage reporting with HTML and XML outputs
- Custom markers for unit, integration, and slow tests
- Strict configuration options
- Test discovery patterns for
-
Coverage Settings: Set up coverage.py with:
- Source directory configuration
- Exclusion patterns for test files and virtual environments
- Multiple report formats (terminal, HTML, XML)
- Currently set to 0% threshold (should be updated to 80% when adding actual tests)
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Testing Fixtures
Created comprehensive fixtures in conftest.py:
temp_dir: Temporary directory managementmock_config: Mock configuration objectmock_mongo_client: Mock MongoDB clientmock_flask_app: Mock Flask applicationmock_twitter_api: Mock Twitter API clientsample_tweet: Sample tweet datasample_stock_data: Sample stock datareset_environment: Environment variable managementmock_nltk_sentiment: Mock sentiment analyzer
Additional Setup
- Git Ignore: Added comprehensive
.gitignorewith testing artifacts and Claude settings - Validation Tests: Created validation tests to verify the infrastructure works correctly
How to Use
Install Dependencies
poetry install
Run Tests
# Run all tests
poetry run test
# or
poetry run tests
# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run with coverage report
poetry run pytest --cov-report=html
Writing Tests
- Place unit tests in
tests/unit/ - Place integration tests in
tests/integration/ - Use fixtures from
conftest.pyfor common test needs - Mark tests appropriately with
@pytest.mark.unit,@pytest.mark.integration, or@pytest.mark.slow
Notes
- The coverage threshold is currently set to 0% to allow the infrastructure setup to complete. This should be increased to 80% as actual tests are added.
- All pytest options are available when using the poetry run commands
- The project uses Poetry's lock file for reproducible builds (poetry.lock should be committed)