Skip to content

feat: Set up Python testing infrastructure with Poetry and pytest #86

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: main
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 15, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the AWS Icons for PlantUML project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated existing dependencies from scripts/requirements.txt
  • Development Dependencies: Added testing tools as dev dependencies

Testing Framework

  • pytest: Main testing framework with comprehensive configuration
  • pytest-cov: Coverage reporting with 80% threshold requirement
  • pytest-mock: Mocking utilities for unit tests

Project Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and configuration
├── test_infrastructure_validation.py  # Infrastructure validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Configuration

pytest Configuration (in pyproject.toml)

  • Test discovery patterns
  • Coverage settings with HTML and XML reporting
  • Custom markers: unit, integration, slow
  • Strict mode enabled for better error detection

Coverage Configuration

  • Source directory: scripts/
  • Excluded: test files, cache, virtual environments
  • Report formats: terminal, HTML, XML
  • Coverage threshold: 80%

Fixtures (in conftest.py)

  • temp_dir: Temporary directory management
  • mock_config: Sample configuration data
  • sample_yaml_file: YAML file creation
  • sample_svg_content & sample_svg_file: SVG testing
  • mock_env_vars: Environment variable mocking
  • cleanup_test_files: Automatic test file cleanup
  • capture_logs: Log capture for testing
  • mock_http_response: HTTP response mocking

Development Experience

  • Poetry Scripts: Both poetry run test and poetry run tests work
  • Updated .gitignore: Added testing artifacts, virtual environments, IDE files, and Claude settings

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test
    # or
    poetry run tests
  3. Run specific test markers:

    poetry run pytest -m unit
    poetry run pytest -m integration
    poetry run pytest -m "not slow"
  4. Generate coverage reports:

    • HTML report: htmlcov/index.html
    • XML report: coverage.xml

Notes

  • The coverage threshold is set to 80% but can be adjusted in pyproject.toml
  • PyYAML was updated from 5.4.1 to 6.0+ due to build compatibility issues
  • The infrastructure includes validation tests that verify all components are properly configured
  • No actual unit tests for the codebase were created - only the infrastructure setup

Next Steps

Developers can now immediately start writing tests by:

  1. Adding unit tests to tests/unit/
  2. Adding integration tests to tests/integration/
  3. Using the provided fixtures from conftest.py
  4. Following the established patterns and conventions

- Initialized Poetry package manager with pyproject.toml
- Added testing dependencies: pytest, pytest-cov, pytest-mock
- Configured pytest with coverage reporting (80% threshold)
- Created testing directory structure (tests/, unit/, integration/)
- Added comprehensive pytest fixtures in conftest.py
- Updated .gitignore with testing and development patterns
- Added Poetry script commands for running tests
- Created validation tests to verify infrastructure setup
@hakanson
Copy link
Contributor

Thanks for being willing to contribute. This is the type of change that should create a discussion issue first, given I'm not sure we want to change to poetry and the "No actual unit tests for the codebase were created - only the infrastructure setup" note.

Was this an AI generated PR? I noticed it mentioned Claude settings and also didn't update scripts/README.md which is where I would have expected a human to find the original setup instructions. Also you have created other PRs (lizhe00/AnimatableGaussians#56) that mention "🤖 Generated with Claude Code"

@llbbl
Copy link
Author

llbbl commented Jun 16, 2025

Hey! Yeah, Sorry, I know as Python developers we can be a bit picky about package managers. I’m checking for the existence of poetry or UV and then if neither exists, then using poetry since that’s a little bit farther along in the development. There are reasons that I’m doing this that are out of the scope of this discussion.

Yeah, I’ve automated Claude as a part of the Unit Seeker project. I haven’t written about it publicly, but wanted to get things going and then write something this week about it. Still working out a few kinks on finding the right repos to target with the PRs. I figured devs are less going to be less defensive about their projects if all I’m using for is getting testing setup. After testing has been set up, happy to do another more manual PR followup with actual tests, if you’re open to it.

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.

2 participants