Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry #28

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

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

- Set up Poetry as package manager with pyproject.toml
- Migrate dependencies from requirements.txt to Poetry
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (80% threshold)
- Create test directory structure with unit/integration subdirs
- Add comprehensive shared fixtures in conftest.py
- Create validation tests to verify infrastructure
- Update .gitignore with testing and Poetry entries
- Configure Poetry scripts for running 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