Skip to content

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

Open
llbbl wants to merge 1 commit intoarchiki:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure with Poetry#13
llbbl wants to merge 1 commit intoarchiki:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Sep 4, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the TextCraft research project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Created pyproject.toml with Poetry configuration
  • Set up minimal core dependencies (numpy, requests, pyyaml)
  • Configured testing dependencies as a separate group:
    • pytest ^7.4.0 - Main testing framework
    • pytest-cov ^4.1.0 - Coverage reporting
    • pytest-mock ^3.11.1 - Mocking utilities

Testing Configuration

  • Configured pytest in pyproject.toml with:
    • Coverage settings: 80% threshold, HTML/XML reports in htmlcov/ and coverage.xml
    • Test discovery: Automatic discovery of test_*.py and *_test.py files
    • Custom markers: unit, integration, and slow for test categorization
    • Strict options: Enforces marker declarations and configuration validation

Directory Structure

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

Shared Test Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir / temp_file - Temporary file system operations
  • mock_openai_client - Mock OpenAI API client
  • mock_environment - Mock environment configuration
  • sample_crafting_tree - Test data for crafting mechanics
  • mock_alfworld_env / mock_textcraft_env - Mock game environments
  • sample_prompt_data - Mock prompt templates
  • mock_file_system - File system mocking
  • clean_environment - Environment variable cleanup

Development Environment

  • Updated .gitignore with testing artifacts, IDE files, and development environment entries
  • Configured coverage reporting with source filtering and exclusion rules
  • Added Claude Code settings to gitignore

Running Tests

Basic Usage

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=TextCraft

# Run specific test categories
poetry run pytest -m unit        # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow"  # Skip slow tests

Coverage Reports

  • Terminal: Displays coverage summary with missing lines
  • HTML Report: Generated in htmlcov/ directory
  • XML Report: Generated as coverage.xml for CI integration

Validation

All infrastructure validation tests pass, confirming:

  • ✅ pytest installation and configuration
  • ✅ Custom marker functionality (unit, integration, slow)
  • ✅ All shared fixtures work correctly
  • ✅ Coverage reporting generates properly
  • ✅ Project structure is correctly set up
  • ✅ Testing dependencies are available

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing scenarios
  4. Run tests with poetry run pytest
  5. Generate coverage reports to ensure code quality

The testing infrastructure is ready for immediate use and provides a solid foundation for maintaining code quality throughout the project.

- Created pyproject.toml with Poetry configuration and testing dependencies
- Added pytest, pytest-cov, and pytest-mock for comprehensive testing
- Configured pytest with coverage reporting (80% threshold), custom markers, and HTML/XML output
- Set up proper testing directory structure with unit/ and integration/ folders
- Created shared pytest fixtures in conftest.py for common testing needs
- Added validation tests to ensure testing infrastructure works correctly
- Updated .gitignore with testing artifacts and development environment entries
- Configured coverage reporting with source filtering and exclusion rules
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