Skip to content

feat: Set up comprehensive Python testing infrastructure with Poetry #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 25, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the SimpleWebSocketServer project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use environment where developers can immediately start writing unit and integration tests.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration, migrating from the existing setup.py
  • Python Version: Updated to require Python 3.7+ for compatibility with modern testing tools
  • Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies

Testing Framework

  • pytest Configuration:
    • Configured test discovery patterns
    • Set up coverage reporting with HTML and XML outputs
    • Added custom markers: unit, integration, and slow
    • Configured strict mode and output formatting
    • Set initial coverage threshold to 9% (should be updated to 80% as tests are added)

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared pytest fixtures
├── test_infrastructure_validation.py  # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Fixtures and Utilities

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory management
  • mock_websocket: Mock WebSocket client
  • mock_server: Mock WebSocket server
  • sample_config: Configuration examples
  • mock_ssl_context: SSL context mocking
  • capture_output: Output capture utility
  • sample_websocket_message: Sample message data
  • reset_modules: Module isolation between tests

Development Experience

  • Added Poetry scripts for running tests: both poetry run test and poetry run tests work
  • Updated .gitignore to exclude test artifacts while keeping poetry.lock tracked
  • Coverage reports generate in both terminal and HTML format

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test
    # or
    poetry run tests
  3. Run specific test markers:

    poetry run pytest -m unit      # Run only unit tests
    poetry run pytest -m integration  # Run only integration tests
    poetry run pytest -m "not slow"   # Skip slow tests
  4. View coverage report:

    • Terminal: Automatically shown after test run
    • HTML: Open htmlcov/index.html in a browser

Notes

  • The coverage threshold is currently set to 9% to allow the infrastructure setup to pass. This should be updated to 80% (as configured in the TODO comment) once actual tests are written.
  • All validation tests pass, confirming the infrastructure is working correctly.
  • The setup supports Python 3.7+ to ensure compatibility with modern testing tools.
  • Poetry lock file is intentionally tracked in version control for reproducible builds.

- Added Poetry as the package manager with pyproject.toml configuration
- Configured pytest with coverage reporting and custom markers
- Created test directory structure (unit/integration)
- Added shared pytest fixtures in conftest.py
- Updated .gitignore with testing and Claude-related entries
- Added validation tests to verify infrastructure works correctly
- Configured test scripts for both 'poetry run test' and 'poetry run tests'
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