pyioc
pyioc copied to clipboard
Add comprehensive Python testing infrastructure
Add Comprehensive Python Testing Infrastructure
Summary
This PR sets up a complete, modern testing infrastructure for the pyioc project, providing developers with all necessary tools and configurations to write and run tests effectively.
Key Changes Made
Package Management
-
Added Poetry configuration in
pyproject.tomlwith proper dependency management - Migrated from Python 2.7 to Python 3.8+ for better compatibility and security
- Organized dependencies into production and development groups
Testing Framework
- pytest as the main testing framework with comprehensive configuration
- pytest-cov for coverage reporting with 80% threshold
- pytest-mock for advanced mocking capabilities
-
Custom test markers:
unit,integration,slowfor test categorization
Directory Structure
-
tests/- Main testing directory -
tests/unit/- Unit tests -
tests/integration/- Integration tests -
tests/conftest.py- Shared fixtures and test utilities
Coverage Configuration
-
Multiple report formats: Terminal, HTML (
htmlcov/), XML (coverage.xml) -
Source tracking for
client,server, andutilsmodules - Exclusions for test files, build artifacts, and common patterns
- 80% coverage threshold to ensure code quality
Shared Test Fixtures
-
temp_dirandtemp_filefor filesystem testing -
mock_configfor configuration testing -
mock_ioc_filewith sample IOC XML content -
sample_ioc_dirandsample_conf_dirfor directory-based tests - SSL and SOAP mocking utilities for network testing
Development Workflow
- Clean .gitignore with testing-related entries
- Validation tests to verify infrastructure setup
- Environment reset fixtures for test isolation
How to Run Tests
Basic Commands
# Install dependencies
poetry install
# Run all tests
poetry run pytest
# Run with verbose output
poetry run pytest -v
# Run specific test types
poetry run pytest -m unit # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow" # Exclude slow tests
Coverage Reports
# Generate coverage report
poetry run pytest --cov
# Generate HTML coverage report
poetry run pytest --cov --cov-report=html
# View coverage in browser
open htmlcov/index.html
Test Discovery
The configuration automatically discovers:
- Files matching
test_*.pyor*_test.py - Classes prefixed with
Test - Functions prefixed with
test_
Validation
✅ Dependencies installed successfully
✅ All validation tests pass
✅ Coverage reporting works correctly
✅ Test markers function properly
✅ Shared fixtures available and working
Notes
- Python 3.8+ is now required (upgraded from Python 2.7)
- Some legacy dependencies (SOAPpy, M2Crypto) were removed due to Python 3 compatibility issues
- poetry.lock file is tracked in git for reproducible builds
- Ready for immediate use - developers can start writing tests right away
Future Considerations
- Consider adding
toxfor multi-version testing - May want to add
blackandflake8for code formatting/linting - Integration with CI/CD pipelines can leverage the XML coverage reports
The testing infrastructure is now complete and ready for development teams to write comprehensive tests for the pyioc codebase.