mlsql icon indicating copy to clipboard operation
mlsql copied to clipboard

feat: Set up Python testing infrastructure with Poetry and pytest

Open llbbl opened this issue 5 months ago • 0 comments

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the text-to-SQL models project using Poetry for dependency management and pytest as the testing framework.

Changes Made

Package Management

  • Configured Poetry as the package manager with package-mode = false (dependency management only)
  • Created pyproject.toml with project metadata and dependencies
  • Added development dependencies: pytest, pytest-cov, pytest-mock

Testing Framework Setup

  • Directory Structure:

    tests/
    ├── __init__.py
    ├── conftest.py
    ├── test_infrastructure.py
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    
  • pytest Configuration:

    • Test discovery patterns: test_*.py and *_test.py
    • Custom markers: unit, integration, slow
    • Verbose output with short traceback format
    • Coverage settings configured (ready for future use)

Test Fixtures (conftest.py)

Created comprehensive fixtures for common testing scenarios:

  • temp_dir: Temporary directory management
  • sample_csv_file: CSV file creation for testing
  • sample_sqlite_db: SQLite database with test data
  • mock_config: Configuration dictionary
  • mock_api_request/mock_sql_response: API testing helpers
  • mock_model_predictions: Model output mocking
  • reset_environment: Environment variable isolation
  • captured_logs: Log capture utility
  • mock_http_response: HTTP response mocking

Validation

  • Created test_infrastructure.py with 12 validation tests
  • All tests pass successfully, confirming proper setup

Other Changes

  • Created .gitignore with comprehensive Python patterns
  • Added Claude-specific entries to gitignore

How to Use

  1. Install dependencies:

    poetry install
    
  2. Run all tests:

    poetry run pytest
    

    or

    poetry run test  # or 'poetry run tests'
    
  3. Run specific test categories:

    poetry run pytest -m unit
    poetry run pytest -m integration
    poetry run pytest -m "not slow"
    
  4. Run with coverage (when ready):

    poetry run pytest --cov=irnet --cov=valuenet
    

Notes

  • The infrastructure is ready for developers to start writing tests
  • No actual unit tests for the codebase were created - only infrastructure setup
  • The main project dependencies (Flask, transformers, etc.) were not included to avoid installation issues during setup
  • Coverage reporting is configured but not enforced initially

Next Steps

  1. Developers can now write unit tests in tests/unit/
  2. Integration tests go in tests/integration/
  3. Use the provided fixtures for common testing patterns
  4. Add project dependencies to pyproject.toml as needed

llbbl avatar Jun 27 '25 13:06 llbbl