Skip to content

feat: Set up Python testing infrastructure with Poetry - #145

Open
llbbl wants to merge 1 commit into
Elico-Corp:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up Python testing infrastructure with Poetry#145
llbbl wants to merge 1 commit into
Elico-Corp:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Sep 3, 2025

Copy link
Copy Markdown

Python Testing Infrastructure Setup

Summary

This PR establishes a complete testing infrastructure for the Odoo auto-addons Python project using Poetry as the package manager. The infrastructure provides a ready-to-use testing environment where developers can immediately start writing and running tests.

Changes Made

Package Management

  • Created pyproject.toml with Poetry configuration
  • Migrated dependencies from sources/pip.txt to Poetry format:
    • erppeek==1.6.3
    • OdooRPC==0.6.0
    • py3o.template==0.9.11
    • py3o.types==0.1.1

Testing Dependencies Added

  • pytest ^7.0.0 - Main testing framework
  • pytest-cov ^4.0.0 - Coverage reporting
  • pytest-mock ^3.10.0 - Mocking utilities

Testing Configuration

  • pytest configuration in pyproject.toml:

    • Test discovery patterns (test_*.py, *_test.py)
    • Coverage settings with 80% threshold
    • HTML, XML, and terminal coverage reports
    • Custom markers: unit, integration, slow
    • Strict options for better test reliability
  • Coverage configuration:

    • Source tracking for auto_addons module
    • Exclusion of test files and virtual environments
    • Comprehensive reporting options

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir - Temporary directory for test isolation
  • mock_subprocess - Mock subprocess calls
  • mock_os_path - Mock filesystem operations
  • sample_oca_dependencies - Sample OCA dependency configurations
  • mock_file_operations - Mock file read/write operations
  • mock_git_operations - Mock git command operations
  • repo_config - Repository configuration for testing
  • odoo_paths - Odoo-related path configurations

Infrastructure Validation

  • Created validation tests to ensure all components work properly
  • Tests cover pytest functionality, fixtures, markers, and project structure
  • All validation tests pass successfully

Additional Updates

  • Updated .gitignore with testing-related entries:
    • .pytest_cache/, coverage reports, virtual environments
    • IDE files, Claude Code settings
  • Poetry lock file tracking enabled (not in .gitignore)

Running Tests

Install Dependencies

poetry install

Run Tests

# Standard command
poetry run pytest

# Alternative command  
poetry run python -m pytest

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

# Run specific test types
poetry run pytest -m unit          # Only unit tests
poetry run pytest -m integration   # Only integration tests  
poetry run pytest -m "not slow"    # Exclude slow tests

Coverage Reports

  • Terminal: Shows missing lines and coverage percentage
  • HTML: Generated in htmlcov/ directory
  • XML: Generated as coverage.xml for CI/CD integration

Development Workflow

  1. Write tests in appropriate directories (tests/unit/, tests/integration/)
  2. Use shared fixtures from conftest.py for common test scenarios
  3. Tag tests with appropriate markers (@pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow)
  4. Run tests regularly during development
  5. Check coverage to ensure adequate test coverage (80% minimum)

Notes

  • The existing auto_addons code contains Python 2 syntax that causes import warnings, but this doesn't affect the testing infrastructure functionality
  • Coverage configuration excludes the legacy files to focus on new development
  • All standard pytest options and plugins are available through the Poetry environment
  • The infrastructure supports both individual test file execution and full test suite runs

Testing Infrastructure Validation

✅ All validation tests pass
✅ pytest and plugins properly installed
✅ Coverage reporting functional
✅ Directory structure correct
✅ Shared fixtures working
✅ Custom markers configured
✅ Poetry commands functional

- Add pyproject.toml with Poetry configuration and testing dependencies
- Configure pytest with coverage reporting, custom markers, and strict options
- Set up comprehensive testing directory structure (tests/, unit/, integration/)
- Create shared fixtures in conftest.py for common testing scenarios
- Add validation tests to verify infrastructure functionality
- Update .gitignore with testing and development entries
- Migrate existing pip dependencies to Poetry management
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