Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: set up comprehensive Python testing infrastructure with Poetry #84

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
llbbl wants to merge 1 commit into microsoft:main
base: main
Choose a base branch
Loading
from UnitSeeker:add-testing-infrastructure

Conversation

Copy link

@llbbl llbbl commented Jun 16, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the P3 (Programming Puzzles and Code Competitions) 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
  • Dependencies: Migrated core dependencies from existing requirements files
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock

Testing Configuration

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML and XML output formats
    • Custom markers for unit, integration, and slow tests
    • Strict mode options for better test quality
  • Coverage Configuration:

    • Source directories: generators and solvers
    • Exclusions for test files and common patterns
    • Detailed reporting with line-by-line coverage

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • temp_file: Temporary file with test content
  • mock_config: Mock configuration dictionary
  • sample_puzzle_data: Sample puzzle data for testing
  • sample_code_snippet: Sample code for testing
  • mock_environment_variables: Mock environment variables
  • project_root, generators_path, solvers_path: Path fixtures
  • clean_imports: Import cleanup for test isolation
  • reset_random_seed: Reproducible random seeds

Poetry Commands

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work)

Additional Configuration

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, coverage.xml, htmlcov/)
    • Claude settings (.claude/*)
    • Note: poetry.lock is NOT ignored (should be in version control)

Testing the Infrastructure

Installation

poetry install

Running Tests

# Run all tests
poetry run test
# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run with coverage
poetry run pytest --cov
# Run specific test file
poetry run pytest tests/test_infrastructure_validation.py

Validation Tests

The PR includes comprehensive validation tests that verify:

  • pytest is properly installed and configured
  • Project modules can be imported
  • All fixtures are available and working
  • Custom markers are configured
  • Coverage reporting is set up
  • Various pytest features work correctly

Notes

  1. orderedset Dependency: The orderedset package from the original requirements had build issues on the current platform. It has been commented out in favor of using Python's built-in OrderedDict when needed.

  2. Coverage Thresholds: The 80% coverage threshold has been temporarily disabled in the configuration since this PR only sets up the infrastructure without implementing actual tests for the codebase.

  3. Deprecation Warnings: Some existing code has deprecation warnings (invalid escape sequences). These are from the existing codebase and should be addressed in a separate PR.

Next Steps

With this testing infrastructure in place, developers can now:

  1. Write unit tests for individual modules
  2. Create integration tests for complex workflows
  3. Add performance benchmarks using the slow marker
  4. Monitor code coverage and improve test quality
  5. Use the shared fixtures to reduce test boilerplate

The infrastructure is designed to be extensible and can be enhanced with additional fixtures, plugins, and configurations as needed.

- Add Poetry as package manager with pyproject.toml configuration
- Configure pytest with coverage reporting and custom markers
- Create testing directory structure (tests/unit, tests/integration)
- Add comprehensive conftest.py with reusable fixtures
- Set up Poetry script commands for running tests
- Update .gitignore with testing and Claude settings
- Add validation tests to verify infrastructure setup
Copy link
Author

llbbl commented Jun 16, 2025

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /