Skip to content

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

Open
llbbl wants to merge 1 commit intosublimehq:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure with Poetry#224
llbbl wants to merge 1 commit intosublimehq:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 30, 2025

Add Python Testing Infrastructure to Vintage

Summary

This PR sets up a comprehensive testing infrastructure for the Vintage project using modern Python tooling. The setup provides a solid foundation for writing and maintaining tests, with proper dependency management, test organization, and coverage reporting.

Changes Made

Package Management

  • Poetry configured as the package manager via pyproject.toml
  • Development dependencies properly isolated from production code
  • Scripts configured for easy test execution

Testing Framework

  • pytest as the main testing framework with the following features:
    • Custom markers for test categorization (unit, integration, slow)
    • Automatic test discovery in the tests/ directory
    • Strict configuration for robust testing

Coverage Reporting

  • pytest-cov configured for comprehensive coverage analysis:
    • 80% coverage threshold requirement
    • Multiple output formats: terminal, HTML, and XML
    • Proper exclusions for test files and generated code

Test Organization

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

Fixtures and Utilities

The conftest.py file provides comprehensive fixtures for testing Sublime Text plugins:

  • temp_dir and temp_file - Temporary file system resources
  • mock_sublime - Mocked Sublime Text API
  • mock_sublime_plugin - Mocked plugin API
  • mock_view, mock_edit, mock_window - Common Sublime objects
  • mock_settings - Settings management
  • sample_vintage_state - Vintage-specific state object
  • mock_registers - Vintage register system

Development Workflow

  • Updated .gitignore with comprehensive Python and testing patterns
  • Poetry lock file tracks exact dependency versions for reproducibility

How to Use

Installation

# Install Poetry if not already installed
curl -sSL https://install.python-poetry.org | python3 -

# Install project dependencies
poetry install

Running Tests

# Run all tests
poetry run test

# Run with verbose output
poetry run tests -v

# Run specific test markers
poetry run pytest -m unit        # Only unit tests
poetry run pytest -m integration # Only integration tests
poetry run pytest -m "not slow"  # Skip slow tests

# Run specific test file
poetry run pytest tests/test_setup_validation.py

# Run without coverage
poetry run pytest --no-cov

Coverage Reports

After running tests, coverage reports are available in:

  • Terminal output (automatically shown)
  • htmlcov/index.html - Interactive HTML report
  • coverage.xml - Machine-readable XML format

Notes

  • The project uses Poetry for modern dependency management, ensuring reproducible builds
  • Test infrastructure is separate from the main codebase to maintain clean separation
  • All Sublime Text APIs are properly mocked to enable testing without the editor
  • The 80% coverage threshold encourages comprehensive testing while remaining achievable
  • Validation tests ensure the infrastructure remains functional

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests for individual functions and classes
  2. Create integration tests for plugin commands
  3. Test edge cases and error handling
  4. Maintain high code quality through coverage requirements

The testing setup follows Python best practices and provides a solid foundation for maintaining and improving the Vintage plugin.

- Initialize Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with custom markers (unit, integration, slow)
- Set up coverage reporting with 80% threshold and multiple output formats
- Create testing directory structure with unit/integration separation
- Add comprehensive conftest.py with Sublime Text-specific fixtures
- Create validation tests to verify infrastructure setup
- Update .gitignore with testing and development artifacts
- Configure Poetry scripts for running tests via 'poetry run test(s)'
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

Comments