Skip to content

feat: Set up comprehensive Python testing infrastructure#3

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

feat: Set up comprehensive Python testing infrastructure#3
llbbl wants to merge 1 commit into
Ridter:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Jun 24, 2025

Copy link
Copy Markdown

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Redis RCE Python project, enabling developers to immediately start writing and running tests with modern tooling.

Changes Made

Package Management

  • Poetry configured as the package manager via pyproject.toml
  • Migrated existing dependencies from requirements.txt
  • Removed argparse dependency (built-in to Python 3.8+)
  • Set package-mode = false for script-based project

Testing Framework

  • pytest as the main testing framework
  • pytest-cov for code coverage reporting
  • pytest-mock for mocking utilities
  • poethepoet for task running

Directory Structure

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

Configuration (pyproject.toml)

  • pytest settings:

    • Test discovery patterns configured
    • Coverage reporting (HTML, XML, terminal)
    • Custom markers: unit, integration, slow
    • Strict mode enabled for better error detection
  • coverage settings:

    • Source coverage for main module
    • Exclusions for test files, virtual environments, and build artifacts
    • HTML reports in htmlcov/ directory
    • XML reports for CI integration

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_config: Sample configuration dictionary
  • mock_redis_client: Mock Redis client for testing
  • mock_socket: Mock network socket
  • sample_redis_response: Redis protocol test data
  • mock_args: Mock command-line arguments
  • reset_environment: Environment variable isolation
  • capture_stdout: Stdout capture utility
  • isolation: Complete test isolation with temp directory

Development Workflow

  • Updated .gitignore with:
    • Python artifacts (__pycache__/, *.pyc, etc.)
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/)
    • Virtual environments
    • IDE files
    • Claude directory (.claude/*)

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests
poetry run poe test

# Alternative command
poetry run poe tests

# Run with specific options
poetry run pytest -v --no-cov

# Run specific test markers
poetry run pytest -m unit
poetry run pytest -m integration

Coverage Reports

  • Terminal: Automatically shown after test run
  • HTML: Open htmlcov/index.html in browser
  • XML: Available at coverage.xml for CI tools

Notes

  • Coverage threshold is currently disabled for validation tests
  • The main script (redis-rce.py) needs refactoring into modules for proper testing
  • All pytest standard options are available
  • Tests automatically get marked based on their directory (unit/ or integration/)

Next Steps

  1. Refactor redis-rce.py into testable modules
  2. Write comprehensive unit tests for all functions
  3. Add integration tests for Redis interactions
  4. Set up CI/CD pipeline with coverage reporting
  5. Add pre-commit hooks for test execution

- Add Poetry package manager with pyproject.toml configuration
- Create test directory structure with unit/integration subdirectories
- Configure pytest with coverage, markers, and custom fixtures
- Add development dependencies: pytest, pytest-cov, pytest-mock
- Set up poe tasks for running tests with `poetry run poe test`
- Update .gitignore with testing and Claude-specific entries
- Add validation tests to verify infrastructure works correctly
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