Skip to content

feat: Set up complete Python testing infrastructure with Poetry - #187

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

feat: Set up complete Python testing infrastructure with Poetry#187
llbbl wants to merge 1 commit into
jbuchermn:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Jun 23, 2025

Copy link
Copy Markdown

Set Up Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the newm Wayland compositor project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration
  • Dependencies Migration: Migrated all dependencies from requirements.txt and setup.py to Poetry
  • Entry Points: Created proper entry point modules (__main__.py) for both newm and newm_panel_basic packages

Testing Framework

  • Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies
  • Pytest Configuration: Configured pytest with:
    • Test discovery patterns
    • Coverage reporting (HTML, XML, terminal)
    • Custom markers for unit, integration, and slow tests
    • Strict configuration options

Testing Structure

  • Created organized test directory structure:
    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures
    ├── test_setup_validation.py  # Infrastructure validation
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing needs:

  • temp_dir: Temporary directory management
  • mock_config_dir, mock_cache_dir, mock_runtime_dir: XDG directory mocking
  • sample_config_file: Sample newm configuration
  • mock_display: Wayland display mock
  • mock_dbus_session: D-Bus session mock
  • mock_pam_handle: PAM authentication mock
  • mock_cairo_surface: Cairo surface mock
  • mock_gesture_event: Gesture event mock
  • clean_environment: Environment variable cleanup
  • capture_logs: Log capturing utility

Other Changes

  • Updated .gitignore: Added comprehensive entries for:
    • Testing artifacts (.pytest_cache, coverage files)
    • Claude settings
    • Virtual environments
    • IDE files
    • Python packaging artifacts

How to Use

Installing Dependencies

# Install all dependencies including dev dependencies
poetry install

Running Tests

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

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

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

Coverage Reports

After running tests with coverage, reports are generated in:

  • Terminal output (with --cov flag)
  • HTML report: htmlcov/index.html
  • XML report: coverage.xml

Notes

  • The validation tests handle missing optional dependencies (like pywm) gracefully
  • Coverage threshold is currently set to 0% to allow initial setup without failing
  • The infrastructure is ready for developers to start writing unit and integration tests
  • Both poetry run test and poetry run tests commands are available but currently not working due to Poetry limitations with script aliases

- Add pyproject.toml with Poetry configuration and migrated dependencies
- Configure pytest with coverage reporting and custom markers
- Create tests directory structure with shared fixtures in conftest.py
- Add comprehensive gitignore entries for testing and development
- Include validation tests to verify infrastructure works correctly
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