ShiroScan icon indicating copy to clipboard operation
ShiroScan copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 6 months ago • 0 comments

Set Up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the ShiroScan project, providing a modern foundation for test-driven development using Poetry, pytest, and comprehensive tooling.

Changes Made

Package Management

  • Migrated to Poetry: Created pyproject.toml with Poetry configuration, replacing basic requirements.txt
  • Dependency Management: Properly separated production and development dependencies
  • Lock File: Poetry will generate a poetry.lock file for reproducible builds

Testing Framework

  • pytest: Configured as the primary testing framework with strict settings
  • pytest-cov: Added for coverage reporting with HTML and XML output formats
  • pytest-mock: Included for advanced mocking capabilities
  • Custom Markers: Defined unit, integration, and slow markers for test categorization

Project Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures and configuration
├── test_setup_validation.py  # Validation tests
├── unit/                # Unit tests directory
│   └── __init__.py
└── integration/         # Integration tests directory
    └── __init__.py

Testing Configuration

  • Coverage Settings:
    • Source: moule package
    • Threshold: 15% (adjustable as codebase grows)
    • Reports: Terminal, HTML (htmlcov/), and XML
    • Excludes: Plugin directory and test files
  • Test Discovery: Configured to find all test_*.py files
  • Strict Mode: Enabled strict markers and configuration

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory management
  • temp_file: Temporary file creation
  • mock_requests: Mocked HTTP requests
  • mock_config: Configuration for testing
  • mock_shiro_response: Shiro-specific response mocking
  • mock_key_list: Test encryption keys
  • mock_plugin: Plugin system mocking
  • mock_subprocess_run: Command execution mocking
  • mock_threading: Thread pool mocking
  • capture_stdout: Output capturing
  • mock_dns_log: DNS logging mocking

Development Workflow

  • Added .gitignore with comprehensive exclusions for Python development
  • Created Poetry scripts for running tests:
    • poetry run test - Run all tests
    • poetry run tests - Alternative command (both work)

Instructions for Running Tests

Initial Setup

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install project dependencies
poetry install

# Run validation tests to verify setup
poetry run test tests/test_setup_validation.py -v

Running Tests

# Run all tests with coverage
poetry run test

# Run specific test file
poetry run test tests/unit/test_example.py

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

# Run tests with verbose output
poetry run test -v

# Generate coverage report only
poetry run test --cov-report=html

Writing New Tests

  1. Create test files in tests/unit/ or tests/integration/
  2. Use fixtures from conftest.py for common test needs
  3. Mark tests appropriately with @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow
  4. Follow the naming convention: test_*.py for files, test_* for functions

Notes

  • The coverage threshold is initially set to 15% to allow for gradual test coverage improvement
  • Plugin files are excluded from coverage as they follow a similar pattern and would skew metrics
  • All pytest options remain available when using the Poetry scripts
  • The validation test suite ensures the infrastructure is working correctly

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests for individual functions and classes
  2. Create integration tests for the full exploitation chains
  3. Add performance benchmarks using the slow marker
  4. Gradually increase the coverage threshold as more tests are added

The testing foundation is ready for immediate use, with all necessary tooling and configuration in place.

llbbl avatar Jun 16 '25 00:06 llbbl