Skip to content

feat: Set up complete Python testing infrastructure with Poetry #72

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 17, 2025

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

- Initialize Poetry package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure comprehensive pytest and coverage settings
- Create standard test directory structure (unit/integration)
- Add shared pytest fixtures in conftest.py
- Update .gitignore with testing and development patterns
- Add validation tests to verify infrastructure works
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