Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry #29

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

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 15, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the recommender systems evaluation project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry as the package manager
  • Dependency Migration: Migrated core dependencies from requirements.txt with flexible version constraints
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Setup

  • Directory Structure:

    • Created tests/ directory with unit/ and integration/ subdirectories
    • Added __init__.py files for proper Python package structure
  • Pytest Configuration:

    • Test discovery patterns for multiple naming conventions
    • Coverage settings with 80% threshold
    • HTML and XML coverage report generation
    • Custom markers: unit, integration, slow
    • Strict marker enforcement
  • Shared Fixtures (tests/conftest.py):

    • temp_dir: Temporary directory management
    • mock_config: Configuration dictionary for testing
    • sample_data_dir: Sample CSV files for data testing
    • sample_sparse_matrix: Sparse matrix for recommender testing
    • sample_dataframe: Pandas DataFrame fixture
    • mock_recommender: Mock recommender object
    • mock_evaluator: Mock evaluator object
    • mock_data_reader: Mock data reader
    • capture_logs: Log capture fixture
    • reset_random_seed: Automatic random seed reset
    • And more...
  • Validation Tests: Created comprehensive tests to verify the infrastructure works correctly

Commands

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work)
  • All standard pytest options are available

Instructions for Running Tests

  1. Install dependencies:

    poetry install
  2. Run all tests:

    poetry run test
  3. Run specific test file:

    poetry run pytest tests/test_file.py
  4. Run with coverage:

    poetry run pytest --cov
  5. Run only unit tests:

    poetry run pytest -m unit

Notes

Dependency Compatibility

The original requirements.txt contains legacy dependencies (TensorFlow 1.13.1, Keras 2.2.4, etc.) that require Python <=3.7. The testing infrastructure uses flexible version constraints to work with modern Python versions. For projects requiring the exact legacy versions:

  1. Use a Python 3.7 virtual environment
  2. Install from original requirements.txt: pip install -r requirements.txt
  3. Or use Docker containers with appropriate base images

Coverage Configuration

  • Coverage reports exclude test files, Cython builds, and virtual environments
  • HTML reports are generated in htmlcov/
  • XML reports for CI integration are generated as coverage.xml
  • Default threshold is 80% but can be overridden with --cov-fail-under

Next Steps

Developers can now immediately start writing tests for the codebase. The infrastructure provides all necessary tools and configurations for comprehensive testing.

- Set up Poetry as package manager with flexible dependency versions
- Configure pytest with coverage reporting and custom markers
- Create test directory structure with unit/integration separation
- Add comprehensive pytest fixtures for common testing scenarios
- Configure coverage thresholds and reporting formats
- Add Poetry scripts for running tests via 'poetry run test(s)'
- Update .gitignore with testing and Poetry-related entries
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