ssh-ident icon indicating copy to clipboard operation
ssh-ident copied to clipboard

feat: Set up complete Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Set Up Python Testing Infrastructure

Summary

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

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry setup in package-mode=false (since ssh-ident is a standalone script)
  • No Migration Required: No existing requirements.txt or setup.py files were found

Testing Dependencies

Added as development dependencies:

  • pytest ^8.0.0 - Core testing framework
  • pytest-cov ^5.0.0 - Coverage reporting
  • pytest-mock ^3.14.0 - Mocking utilities

Testing Configuration

Configured in pyproject.toml:

  • pytest settings:
    • Test discovery in tests/ directory
    • Coverage reporting (HTML, XML, terminal)
    • Custom markers: unit, integration, slow
    • Strict mode with verbose output
  • coverage settings:
    • Source coverage for project root
    • Exclusions for test files, virtual envs, and build artifacts
    • HTML reports in htmlcov/, XML in coverage.xml

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures
├── test_setup_validation.py  # Infrastructure validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Testing Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir - Temporary directory management
  • temp_file - Temporary file creation
  • mock_env_vars - Environment variable mocking
  • mock_home_dir - Mock home directory
  • mock_ssh_dir - Mock .ssh directory
  • mock_config - Configuration mocking
  • sample_ssh_key - Sample SSH key file
  • sample_ssh_config - Sample SSH config
  • capture_stdout - Stdout capture utility
  • reset_modules - Module reset between tests

Additional Setup

Updated .gitignore with:

  • Testing artifacts: .pytest_cache/, .coverage, htmlcov/, coverage.xml
  • Python artifacts: __pycache__/, *.py[cod], *.egg-info/
  • Development: virtual environments, IDE files, build artifacts
  • Claude settings: .claude/*

How to Use

  1. Install dependencies:

    poetry install
    
  2. Run tests:

    poetry run pytest
    
  3. Run tests with specific markers:

    poetry run pytest -m unit
    poetry run pytest -m integration
    poetry run pytest -m "not slow"
    
  4. View coverage report:

    # After running tests, open the HTML report
    open htmlcov/index.html
    

Validation

All validation tests pass successfully:

  • Testing tools are installed and available
  • Directory structure is created correctly
  • Fixtures are working properly
  • Markers are configured
  • Coverage reporting is functional

Notes

  • Coverage threshold is currently set to 0% to allow initial setup without failing
  • The project uses Poetry in non-package mode since ssh-ident is a standalone script
  • Standard pytest options are available for all test runs
  • The infrastructure is ready for developers to start writing actual unit and integration tests

llbbl avatar Jun 17 '25 17:06 llbbl