ShiroScan
ShiroScan copied to clipboard
feat: Set up comprehensive Python testing infrastructure
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.tomlwith Poetry configuration, replacing basicrequirements.txt - Dependency Management: Properly separated production and development dependencies
- Lock File: Poetry will generate a
poetry.lockfile 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, andslowmarkers 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:
moulepackage - Threshold: 15% (adjustable as codebase grows)
- Reports: Terminal, HTML (
htmlcov/), and XML - Excludes: Plugin directory and test files
- Source:
- Test Discovery: Configured to find all
test_*.pyfiles - Strict Mode: Enabled strict markers and configuration
Shared Fixtures (conftest.py)
temp_dir: Temporary directory managementtemp_file: Temporary file creationmock_requests: Mocked HTTP requestsmock_config: Configuration for testingmock_shiro_response: Shiro-specific response mockingmock_key_list: Test encryption keysmock_plugin: Plugin system mockingmock_subprocess_run: Command execution mockingmock_threading: Thread pool mockingcapture_stdout: Output capturingmock_dns_log: DNS logging mocking
Development Workflow
- Added
.gitignorewith comprehensive exclusions for Python development - Created Poetry scripts for running tests:
poetry run test- Run all testspoetry 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
- Create test files in
tests/unit/ortests/integration/ - Use fixtures from
conftest.pyfor common test needs - Mark tests appropriately with
@pytest.mark.unit,@pytest.mark.integration, or@pytest.mark.slow - Follow the naming convention:
test_*.pyfor 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:
- Write unit tests for individual functions and classes
- Create integration tests for the full exploitation chains
- Add performance benchmarks using the
slowmarker - 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.