WPForce
WPForce copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up a comprehensive testing infrastructure for the WPForce project using modern Python development tools and practices. The infrastructure provides a solid foundation for writing and maintaining tests, with proper dependency management, test organization, and coverage reporting.
Changes Made
Package Management
- Poetry Configuration: Added
pyproject.tomlwith Poetry as the package manager - Dependency Migration: Migrated the existing
requestsdependency to Poetry - Development Dependencies: Added pytest ecosystem tools as dev dependencies
Testing Framework
- pytest: Main testing framework with comprehensive configuration
- pytest-cov: Coverage reporting with HTML and XML output formats
- pytest-mock: Mocking utilities for isolated unit tests
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Configuration Details
pytest Configuration
- Test discovery patterns for flexible file naming
- Custom markers:
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.slow - Coverage reporting with multiple formats
- Strict mode for better error detection
Coverage Settings
- Source tracking configured for the tests directory
- Exclusions for virtual environments and cache files
- HTML reports generated in
htmlcov/ - XML reports for CI integration
Shared Fixtures (conftest.py)
temp_dir: Temporary directory managementmock_config: Configuration object mockingmock_wordpress_site: WordPress response mockingmock_http_session: HTTP request mockingsample_passwords_file/sample_usernames_file: Test file generationcapture_stdout: Output capture for CLI testing- Additional utilities for testing
Version Control
- Comprehensive
.gitignorefor Python projects - Excludes test artifacts, coverage reports, and virtual environments
- Includes Claude-specific exclusions
How to Use
Installation
# Install Poetry (if not already installed)
pip install poetry
# Install project dependencies
poetry install
Running Tests
# Run all tests
poetry run test
# Alternative command (both work)
poetry run tests
# Run with specific options
poetry run pytest -v # Verbose output
poetry run pytest -k "test_name" # Run specific test
poetry run pytest -m unit # Run only unit tests
poetry run pytest -m integration # Run only integration tests
Coverage Reports
After running tests, coverage reports are available in:
- Terminal output (with missing lines)
htmlcov/index.html(detailed HTML report)coverage.xml(for CI tools)
Notes
- Python Version: The project is configured for Python 3.8+ (the original code is Python 2.7, which needs migration)
- Coverage Threshold: Currently disabled due to legacy Python 2 code parsing issues
- Poetry Lock: The
poetry.lockfile should be committed for reproducible builds - Test Organization: Tests are organized into unit and integration directories for better structure
Next Steps
- Migrate the existing Python 2.7 code to Python 3.8+
- Write unit tests for
wpforce.pyfunctionality - Write unit tests for
yertle.pyfunctionality - Add integration tests for the complete workflows
- Set up CI/CD pipeline with the coverage reports
- Re-enable coverage threshold once tests are written
Validation
The setup includes validation tests that verify:
- Python version requirements
- Project structure integrity
- Testing framework installation
- Plugin availability
- Fixture functionality
- Configuration correctness
All validation tests pass successfully, confirming the infrastructure is ready for use.