ITADN

feat: Add comprehensive Python testing infrastructure with Poetry

#64Pull Requestllbbl 创建于 2025-06-29
L
llbblcommented
# Add Python Testing Infrastructure ## Summary This PR establishes a comprehensive testing infrastructure for the QQ/NTQQ database decryption project using Poetry for package management and pytest for testing. ## Changes Made ### Package Management - **Poetry Setup**: Created `pyproject.toml` with Poetry configuration - **Dependencies**: Added testing dependencies as development requirements: - `pytest` (^7.4.3) - Core testing framework - `pytest-cov` (^4.1.0) - Coverage reporting - `pytest-mock` (^3.12.0) - Mocking utilities ### Testing Configuration - **Test Discovery**: Configured pytest to find tests in the `tests/` directory - **Custom Markers**: Added three markers for test categorization: - `unit` - For unit tests testing individual components - `integration` - For integration tests testing multiple components - `slow` - For tests that take longer to run - **Coverage Settings**: - HTML and XML report generation - 80% coverage threshold (currently set to 0% until source code is added) - Exclusions for test files, virtual environments, and common patterns ### Directory Structure ``` tests/ ├── __init__.py ├── conftest.py # Shared fixtures ├── test_setup_validation.py # Infrastructure validation ├── unit/ │ └── __init__.py └── integration/ └── __init__.py src/ └── __init__.py # Package marker for coverage ``` ### Shared Fixtures (conftest.py) - `temp_dir` - Temporary directory management - `test_data_dir` - Access to test data directory - `mock_config` - Mock configuration dictionary - `sample_db_key` - Sample encryption key for testing - `mock_env_vars` - Environment variable mocking - `create_test_file` - Factory for creating test files - `reset_imports` - Clean import state between tests - `capture_logs` - Log message capturing - `mock_platform` - Cross-platform testing support - `benchmark_timer` - Simple performance timing ### Development Experience - **Test Commands**: Both `poetry run test` and `poetry run tests` work - **Coverage Reports**: Automatically generated in `htmlcov/` and `coverage.xml` - **Validation Tests**: 14 tests verify all infrastructure components work correctly ### Git Configuration - Updated `.gitignore` with comprehensive patterns for: - Testing artifacts (`.pytest_cache/`, coverage files) - Python artifacts (`__pycache__/`, `*.pyc`) - Virtual environments - IDE files - Build artifacts - Claude settings (`.claude/*`) - Note: `poetry.lock` is intentionally NOT ignored to ensure reproducible builds ## Instructions for Use 1. **Install dependencies**: ```bash poetry install ``` 2. **Run tests**: ```bash poetry run test # or poetry run tests ``` 3. **Run specific test categories**: ```bash poetry run pytest -m unit # Run only unit tests poetry run pytest -m integration # Run only integration tests poetry run pytest -m "not slow" # Skip slow tests ``` 4. **View coverage report**: ```bash # After running tests, open the HTML report open htmlcov/index.html # macOS xdg-open htmlcov/index.html # Linux start htmlcov/index.html # Windows ``` ## Notes - The coverage threshold is currently set to 0% because there's no source code in the `src/` directory yet. When you add source code, update these lines in `pyproject.toml`: - Uncomment line 38: `"--cov-fail-under=80",` - Change line 84 from `fail_under = 0` to `fail_under = 80` - All validation tests pass successfully, confirming the infrastructure is ready for use - The project structure supports both unit and integration testing patterns - Fixtures are designed to be reusable and cover common testing needs ## Next Steps 1. Move existing Python scripts to the `src/` directory with proper package structure 2. Re-enable the 80% coverage threshold 3. Begin writing unit tests for existing functionality 4. Add integration tests for cross-platform scenarios
合并状态:未合并 关闭于 2025-08-25 1 条评论