Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 3, 2025

Add Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the webhook samples repository, enabling developers to easily write and run tests for all Python components.

Changes Made

Package Management

  • Set up Poetry as the package manager with pyproject.toml
  • Migrated dependencies from existing requirements.txt files to Poetry extras:
    • azure: Azure Functions dependencies
    • slack: Slack bot dependencies
    • flask: Flask web server dependencies
    • all: All optional dependencies

Testing Configuration

  • pytest configuration with:
    • Coverage reporting (80% threshold, HTML/XML reports)
    • Custom markers: unit, integration, slow
    • Strict configuration for robust testing
    • Coverage source paths for Developer/ and sample-workflows/

Testing Infrastructure

  • Directory structure:

    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    
  • Comprehensive fixtures in conftest.py:

    • temp_dir: Temporary directory for test files
    • mock_config: Mock configuration settings
    • sample_webhook_payload: Sample ArcGIS webhook data
    • mock_azure_function_context/request: Azure Functions mocks
    • mock_flask_app: Flask application mocks
    • mock_requests_session: HTTP requests mocks
    • mock_slack_client: Slack client mocks
    • mock_environment_variables: Test environment setup
    • json_file: JSON file creation helper
    • mock_hash_validator: Webhook security validation mocks

Development Dependencies

  • pytest ^7.4.0: Main testing framework
  • pytest-cov ^4.1.0: Coverage reporting
  • pytest-mock ^3.11.1: Enhanced mocking utilities

Additional Setup

  • Updated .gitignore with testing artifacts, build files, and Claude Code settings
  • Validation tests to verify infrastructure functionality
  • Poetry.lock included for reproducible builds

Usage Instructions

Installing Dependencies

# Install all dependencies
poetry install

# Install with specific extras
poetry install -E azure
poetry install -E slack  
poetry install -E flask
poetry install -E all

Running Tests

# Run all tests
poetry run pytest

# Run with verbose output
poetry run pytest -v

# Run specific test types
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

# Run with coverage
poetry run pytest --cov

# Run without coverage
poetry run pytest --no-cov

Coverage Reports

  • Terminal: Shows missing line coverage
  • HTML: htmlcov/index.html
  • XML: coverage.xml for CI/CD integration

Validation

The infrastructure includes comprehensive validation tests (tests/test_infrastructure_validation.py) that verify:

  • ✅ pytest functionality and markers
  • ✅ All shared fixtures work correctly
  • ✅ Project structure is properly set up
  • ✅ Coverage configuration is functional
  • ✅ Environment variable mocking
  • ✅ Sample data fixtures

Test Results: All 16 validation tests pass successfully.

Notes

  • Optional dependencies are organized as Poetry extras to avoid conflicts between different sample implementations
  • Coverage threshold set to 80% but can be adjusted per project needs
  • Markers allow selective test execution (unit vs integration vs slow tests)
  • Fixtures provide comprehensive mocking for all webhook sample types (Azure, Slack, Flask)
  • No actual unit tests were written for existing code - this PR only provides the infrastructure

Next Steps

Developers can now:

  1. Write unit tests for existing webhook listeners
  2. Add integration tests for end-to-end scenarios
  3. Use provided fixtures to mock external dependencies
  4. Run tests with confidence using the established patterns

- Set up Poetry as package manager with pyproject.toml
- Configure pytest with coverage reporting, custom markers (unit/integration/slow)
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Create proper test directory structure (tests/unit, tests/integration)
- Add comprehensive shared fixtures in conftest.py
- Set up .gitignore for testing artifacts and Claude Code settings
- Include validation tests to verify infrastructure functionality
- Migrate existing dependencies from requirements.txt files to Poetry extras
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