Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry#206

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

feat: Add comprehensive Python testing infrastructure with Poetry#206
llbbl wants to merge 1 commit into
xNul:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Jun 27, 2025

Copy link
Copy Markdown

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the Palworld save tools project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependencies: Added pytest (7.4.3+), pytest-cov (4.1.0+), and pytest-mock (3.12.0+) as development dependencies
  • Scripts: Configured both poetry run test and poetry run tests commands for running tests

Testing Configuration

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py files
    • Strict markers and configuration
    • Coverage reporting with HTML, XML, and terminal output
    • Custom markers: unit, integration, slow
  • Coverage Settings:

    • Source code coverage tracking
    • Exclusion patterns for test files, virtual environments, and build artifacts
    • HTML report generation in htmlcov/ directory
    • XML report for CI/CD integration

Directory Structure

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

Testing Fixtures (conftest.py)

  • temp_dir: Creates temporary directories for test isolation
  • temp_file: Creates temporary files with custom content
  • mock_json_file: Creates mock JSON files for testing
  • mock_save_file: Creates mock .sav files for testing
  • mock_config: Provides mock configuration dictionaries
  • mock_subprocess: Mocks subprocess calls
  • mock_os_environ: Provides clean environment variables
  • sample_player_data: Sample player data for testing
  • sample_level_data: Sample level/world data for testing
  • cleanup_test_files: Automatic cleanup of test files

Additional Setup

  • Created comprehensive .gitignore with Python, testing, and IDE patterns
  • Added validation tests to verify the infrastructure works correctly
  • Poetry lock file will be generated on first install (not gitignored)

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test
    # or
    poetry run tests
  3. Run specific test markers:

    poetry run pytest -m unit        # Run only unit tests
    poetry run pytest -m integration # Run only integration tests
    poetry run pytest -m "not slow"  # Skip slow tests
  4. View coverage report:

    # After running tests, open the HTML report
    open htmlcov/index.html  # macOS
    xdg-open htmlcov/index.html  # Linux

Notes

  • The testing infrastructure is ready for developers to start writing tests
  • Coverage is currently at 0% as no actual tests for the codebase have been written yet
  • The 80% coverage threshold has been removed from the default configuration to allow gradual test implementation
  • All test files and directories are properly excluded from coverage reporting
  • The validation tests confirm that all components are working correctly

- Set up Poetry package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with custom markers and coverage settings
- Create tests directory structure with unit/integration subdirs
- Add comprehensive pytest fixtures in conftest.py
- Include validation tests to verify setup
- Update .gitignore with Python and testing patterns
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