Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 28, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the XXMI Launcher project, migrating from traditional requirements.txt to modern Poetry package management and setting up pytest as the testing framework.

Changes Made

Package Management

  • Created pyproject.toml with Poetry configuration
  • Migrated all 27 dependencies from requirements.txt to Poetry
  • Properly marked Windows-specific dependencies (pywin32, WMI, winshell)
  • Added development dependencies for testing

Testing Framework

  • pytest - Main testing framework with comprehensive configuration
  • pytest-cov - Coverage reporting with HTML and XML output formats
  • pytest-mock - Mocking utilities for unit tests

Project Structure

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

Testing Configuration (pyproject.toml)

  • Test discovery patterns for flexible naming conventions
  • Coverage settings with reports in multiple formats
  • Custom test markers: @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow
  • Strict mode enabled for better error detection
  • Coverage threshold set to 0% temporarily (with TODO to increase to 80%)

Shared Fixtures (conftest.py)

  • temp_dir - Temporary directory management
  • mock_config_dir - Mock configuration directory
  • mock_app_config - Application configuration mocks
  • mock_game_info - Game information mocks
  • mock_mod_info - Mod information mocks
  • mock_requests_get - Network request mocking
  • mock_subprocess - Subprocess execution mocking
  • mock_logger - Logger mocking
  • mock_window - GUI window mocking
  • clean_environment - Environment variable isolation
  • mock_platform_system - Platform detection mocking

Development Commands

# Install dependencies
poetry install

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

# Run tests with specific markers
poetry run pytest -m unit
poetry run pytest -m integration

# Run with verbose output
poetry run pytest -v

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

Updated .gitignore

Added entries for:

  • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
  • Poetry artifacts (dist/, *.egg-info/)
  • Virtual environments
  • IDE files
  • Claude settings (.claude/*)

Testing the Infrastructure

The validation test suite (test_infrastructure_validation.py) verifies:

  • Python path configuration
  • Project structure existence
  • Fixture availability and functionality
  • Test markers working correctly
  • Import capabilities

All 12 validation tests pass successfully, confirming the infrastructure is properly configured.

Next Steps

  1. Developers can now write unit tests in tests/unit/
  2. Integration tests go in tests/integration/
  3. Coverage threshold should be increased from 0% to 80% as tests are added
  4. The TODO comments in pyproject.toml indicate where to update the coverage threshold

Notes

  • Poetry lock file (poetry.lock) is intentionally not gitignored and should be committed
  • Coverage reports show 0% because no actual unit tests for the codebase were written (only infrastructure validation)
  • Some Python files couldn't be parsed by coverage due to syntax specific to newer Python versions, but this doesn't affect the testing infrastructure
  • The project uses Windows-specific dependencies which are properly marked with platform markers

- Migrated from requirements.txt to Poetry package management
- Added pytest, pytest-cov, and pytest-mock as dev dependencies
- Configured comprehensive pytest and coverage settings
- Created test directory structure with unit/integration subdirectories
- Added shared pytest fixtures in conftest.py
- Set up Poetry scripts for running tests (test/tests commands)
- Updated .gitignore with testing and Poetry-related entries
- Created 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