Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Oct 9, 2025

About UnitSeeker

Hi! This PR is part of the UnitSeeker project, a human-guided initiative to help Python repositories establish testing infrastructure.

Key points:

  • Human-approved: Every PR is manually approved before work begins
  • Semi-automated with oversight: Created and controlled via a homegrown wrapper around Claude Code with human quality control
  • Infrastructure only: This PR intentionally contains only the testing setup without actual unit tests
  • Your repository, your rules: Feel free to modify, reject, or request changes - all constructive feedback is welcome
  • Follow-up support: All responses and discussions are personally written, not automated

Learn more about the project and see the stats on our progress at https://unitseeker.llbbl.com/


Summary

This PR establishes a comprehensive root-level testing infrastructure for the Infinity monorepo using Poetry and pytest. While the individual packages (libs/infinity_emb, libs/client_infinity, etc.) already have their own testing setups, this adds a unified testing framework at the repository root level to orchestrate tests across all packages.

Changes Made

Package Management

  • ✅ Created root-level pyproject.toml with Poetry configuration
  • ✅ Configured Poetry in package-mode = false for monorepo compatibility
  • ✅ Added test dependencies: pytest ^8.0.0, pytest-cov ^6.0.0, pytest-mock ^3.14.0
  • ✅ Generated poetry.lock file (committed for reproducibility)

Testing Configuration

  • ✅ Configured pytest with comprehensive settings in pyproject.toml:

    • Test discovery patterns for both root and lib-level tests
    • Custom markers: unit, integration, slow, performance
    • Verbose output with strict marker and config enforcement
    • Coverage reporting with 80% threshold
    • HTML and XML coverage report generation
  • ✅ Configured coverage.py with:

    • Source directories: libs/
    • Branch coverage enabled
    • Comprehensive omit patterns for test files and dependencies
    • Multiple report formats (terminal, HTML, XML)

Directory Structure

tests/
├── __init__.py              # Package initialization
├── conftest.py              # Shared fixtures and pytest configuration
├── README.md                # Comprehensive testing documentation
├── unit/                    # Unit tests
│   ├── __init__.py
│   └── test_infrastructure.py  # Validation tests
└── integration/             # Integration tests
    ├── __init__.py
    └── test_example.py      # Example integration tests

Shared Test Fixtures

Created comprehensive conftest.py with fixtures:

  • temp_dir - Temporary directory with auto-cleanup
  • temp_file - Temporary file with auto-cleanup
  • mock_env_vars - Mock environment variables
  • mock_config - Mock configuration dictionary
  • sample_data - Sample test data structure
  • project_root - Project root directory path
  • change_test_dir - Change to test directory context

Validation Tests

  • ✅ 19 validation tests created to verify infrastructure
  • ✅ Tests verify fixtures, markers, project structure, and pytest-mock integration
  • ✅ All tests passing

Additional Files

  • ✅ Created tests/README.md with comprehensive documentation covering:

    • How to run tests (with various options)
    • Available markers and fixtures
    • Writing tests (with examples)
    • Coverage configuration
    • CI/CD integration examples
    • Troubleshooting guide
  • ✅ Updated .gitignore to include .claude/* directory

Running Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest

Run with Coverage

poetry run pytest --cov=libs --cov-report=term-missing --cov-report=html

Run Only Unit Tests

poetry run pytest -m unit

Run Only Integration Tests

poetry run pytest -m integration

Exclude Slow Tests

poetry run pytest -m "not slow"

Run Specific Test Directory

# Root-level tests
poetry run pytest tests/

# Package-level tests
poetry run pytest libs/infinity_emb/tests/

Coverage Reporting

The infrastructure is configured to generate multiple coverage report formats:

  1. Terminal Report: Shows coverage summary with missing lines
  2. HTML Report: Generated in htmlcov/ - open htmlcov/index.html in browser
  3. XML Report: Generated as coverage.xml for CI/CD integration

Coverage threshold is set to 80% by default, configurable in pyproject.toml.

Configuration Choices

Poetry Over UV

  • Poetry was chosen because it's already used in the libs/infinity_emb package
  • Provides mature dependency management and lock file support
  • Wide ecosystem support and CI/CD integration

Package Mode: False

  • Root-level pyproject.toml uses package-mode = false since this is a monorepo
  • Individual packages in libs/ maintain their own packaging configuration
  • This allows for centralized test orchestration without packaging the root

Comprehensive Markers

Four test markers are configured:

  • unit - Fast, isolated component tests
  • integration - Multi-component integration tests
  • slow - Long-running tests (can be excluded with -m "not slow")
  • performance - Benchmark and performance tests

Coverage Configuration

  • Covers code in libs/ directory (where actual packages live)
  • Excludes test files, conftest, init, and common patterns
  • Branch coverage enabled for better test quality
  • 80% threshold ensures good test coverage without being overly restrictive

Next Steps

With this infrastructure in place, developers can:

  1. ✅ Write tests in the root tests/ directory for cross-package functionality
  2. ✅ Use shared fixtures from conftest.py in all tests
  3. ✅ Run tests consistently across the entire monorepo
  4. ✅ Generate coverage reports to identify untested code
  5. ✅ Integrate with CI/CD pipelines using coverage.xml

Testing the Infrastructure

This PR includes 19 validation tests that verify the infrastructure itself:

poetry run pytest tests/ -v

Expected output:

============================== test session starts ==============================
...
tests/unit/test_infrastructure.py::TestInfrastructureSetup ... PASSED
tests/unit/test_infrastructure.py::TestCoverageIntegration ... PASSED
tests/unit/test_infrastructure.py::TestProjectStructure ... PASSED
...
============================== 19 passed in 0.02s ==============================

Verification Checklist

  • ✅ Poetry dependencies install successfully
  • ✅ All validation tests pass
  • ✅ Pytest markers work correctly
  • ✅ Shared fixtures are accessible in tests
  • ✅ Coverage reporting generates correctly
  • poetry.lock is tracked in git (not in .gitignore)
  • ✅ Documentation is comprehensive and clear

Questions or Feedback?

Please let me know if you'd like any adjustments to:

  • Coverage thresholds
  • Test markers or organization
  • Fixture implementations
  • Documentation
  • Any other aspect of the testing infrastructure

I'm happy to make modifications to better fit your workflow and preferences!

Set up root-level testing infrastructure for the Infinity monorepo with Poetry
package management, pytest framework, and comprehensive coverage reporting.

- Create pyproject.toml with Poetry configuration in package-mode=false
- Add pytest, pytest-cov, and pytest-mock as test dependencies
- Configure pytest with unit, integration, slow, and performance markers
- Set up coverage reporting with 80% threshold, HTML and XML outputs
- Create tests/ directory structure with unit/ and integration/ subdirectories
- Add comprehensive conftest.py with shared fixtures (temp_dir, mock_config, etc.)
- Create validation tests to verify infrastructure setup
- Add tests/README.md with comprehensive testing documentation
- Update .gitignore to exclude .claude/* directory
- Configure Poetry script commands for easy test execution

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

This PR establishes a comprehensive root-level testing infrastructure for the Infinity monorepo using Poetry and pytest. The changes add a unified testing framework at the repository root to orchestrate tests across all packages, complementing the existing package-level testing setups in libs/infinity_emb and libs/client_infinity. Key additions include a root-level pyproject.toml configured with package-mode = false for monorepo compatibility, pytest configuration with custom markers (unit, integration, slow, performance), comprehensive coverage reporting with 80% threshold, and shared fixtures via conftest.py. The infrastructure includes structured test directories (tests/unit/, tests/integration/) with 19 validation tests to verify proper setup, comprehensive documentation in tests/README.md, and integration with the existing Poetry-based toolchain used throughout the project.

Important Files Changed

Changed Files
Filename Score Overview
pyproject.toml 4/5 Adds root-level Poetry configuration with pytest setup, custom markers, and coverage reporting for monorepo testing orchestration
tests/init.py 5/5 Simple package initialization file to make tests directory a proper Python package
tests/README.md 5/5 Comprehensive testing documentation with usage examples, fixture descriptions, and troubleshooting guide
tests/conftest.py Missing Shared fixtures and pytest configuration - referenced but not shown in the changeset
tests/unit/init.py 5/5 Package initialization file for unit tests directory
tests/unit/test_infrastructure.py 4/5 Validation tests for the new testing infrastructure including fixture, marker, and project structure verification
tests/integration/init.py 5/5 Package initialization file for integration tests directory
tests/integration/test_example.py 5/5 Example integration tests demonstrating fixture usage and project structure validation

Confidence score: 4/5

  • This PR is generally safe to merge with some consideration needed for potential conflicts with existing testing infrastructure
  • Score reflects well-designed testing infrastructure but potential integration concerns with existing package-level pytest configurations in libs/infinity_emb which already has comprehensive testing setup
  • Pay close attention to pyproject.toml for potential dependency conflicts and ensure the new root-level testing doesn't interfere with existing CI/CD workflows

Sequence Diagram

sequenceDiagram
    participant User
    participant "Poetry CLI"
    participant "pytest"
    participant "Coverage"
    participant "Test Files"
    participant "Fixtures"

    User->>+"Poetry CLI": "poetry install"
    "Poetry CLI"->>+"Poetry CLI": "Parse pyproject.toml"
    "Poetry CLI"->>+"Poetry CLI": "Install test dependencies"
    "Poetry CLI"-->>-User: "Dependencies installed"

    User->>+"Poetry CLI": "poetry run pytest"
    "Poetry CLI"->>+pytest: "Execute with config"
    pytest->>+pytest: "Load pyproject.toml config"
    pytest->>+pytest: "Discover test files"
    pytest->>+"Test Files": "Import test modules"
    pytest->>+Fixtures: "Load conftest.py fixtures"
    Fixtures-->>-pytest: "Fixtures available"
    
    loop For each test
        pytest->>+"Test Files": "Execute test function"
        "Test Files"->>+Fixtures: "Request fixture"
        Fixtures-->>-"Test Files": "Provide fixture data"
        "Test Files"-->>-pytest: "Test result"
    end

    pytest->>+Coverage: "Collect coverage data"
    Coverage->>+Coverage: "Track code execution"
    Coverage->>+Coverage: "Generate reports"
    Coverage-->>-pytest: "Coverage metrics"
    
    pytest-->>-"Poetry CLI": "Test results & coverage"
    "Poetry CLI"-->>-User: "Test summary & coverage report"
Loading

7 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +21 to +23
[tool.poetry.scripts]
test = "pytest:main"
tests = "pytest:main"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Poetry scripts pointing directly to pytest:main may not work as expected. Consider using shell commands like 'pytest' instead of module references

Suggested change
[tool.poetry.scripts]
test = "pytest:main"
tests = "pytest:main"
[tool.poetry.scripts]
test = "pytest"
tests = "pytest"
Prompt To Fix With AI
This is a comment left during a code review.
Path: pyproject.toml
Line: 21:23

Comment:
**logic:** Poetry scripts pointing directly to pytest:main may not work as expected. Consider using shell commands like 'pytest' instead of module references

```suggestion
[tool.poetry.scripts]
test = "pytest"
tests = "pytest"
```

How can I resolve this? If you propose a fix, please make it concise.

@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.45%. Comparing base (fcb951c) to head (8dc1a79).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #646      +/-   ##
==========================================
- Coverage   79.54%   79.45%   -0.09%     
==========================================
  Files          43       43              
  Lines        3495     3495              
==========================================
- Hits         2780     2777       -3     
- Misses        715      718       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@llbbl
Copy link
Author

llbbl commented Oct 30, 2025

do i need to update base branch?

@michaelfeil
Copy link
Owner

Not sure about this pr, seems more an added burden to maintain. Would prefer to have less flaky ci and GitHub caches (we test all python versions).

Thanks for opening.

@llbbl
Copy link
Author

llbbl commented Nov 3, 2025

Sorry, It's hard for me to tell if testing is set up or not when everything's in a subfolder. I looked through your test.yaml and didn't see anything that jumped out as a problem. Seems that you have testing set up and going already. I would have to dig into the actions log to see what's causing the issues.

@llbbl llbbl closed this Nov 3, 2025
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.

3 participants