SharPyShell icon indicating copy to clipboard operation
SharPyShell copied to clipboard

feat: Add comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Python Testing Infrastructure with Poetry

Summary

This PR introduces a comprehensive testing infrastructure for the SharPyShell project using Poetry as the package manager and pytest as the testing framework. The setup provides a modern, maintainable foundation for writing and running tests with coverage reporting.

Changes Made

Package Management

  • Poetry Setup: Migrated from requirements.txt to Poetry with pyproject.toml
  • Dependency Management: All existing dependencies preserved and properly categorized
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration:

    • Configured test discovery patterns
    • Set up coverage reporting with 80% threshold
    • Added custom markers for unit, integration, and slow tests
    • Configured output formatting and strict options
  • Coverage Settings:

    • Source directories: core/, modules/, utils/
    • Multiple report formats: terminal, HTML, and XML
    • Excluded test files and __init__.py from coverage

Project Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration object
  • sample_data: Common test data
  • mock_file_system: Mock file system structure
  • mock_network: Network operation mocks
  • mock_subprocess: Subprocess call mocks
  • reset_environment: Environment variable reset
  • capture_logs: Log capture for testing
  • mock_crypto: Cryptographic operation mocks

Running Tests

To run tests using Poetry:

# Install dependencies (first time only)
poetry install

# Run all tests
poetry run test
# or
poetry run tests

# Run tests with specific options
poetry run pytest -v                    # Verbose output
poetry run pytest tests/unit/           # Run only unit tests
poetry run pytest -m integration        # Run only integration tests
poetry run pytest --no-cov             # Run without coverage

Coverage Reports

After running tests, coverage reports are available in:

  • Terminal: Displayed automatically with missing lines
  • HTML: htmlcov/index.html - Interactive HTML report
  • XML: coverage.xml - For CI/CD integration

Notes

  • The 80% coverage threshold is configured but won't block tests initially since no source code tests exist yet
  • Poetry lock file (poetry.lock) is committed for reproducible builds
  • All pytest standard options are available through the Poetry scripts
  • The validation tests confirm that the infrastructure is working correctly

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing scenarios
  4. Run tests with coverage to ensure code quality

llbbl avatar Jun 24 '25 14:06 llbbl