This guide explains how to test the pose_detector.py file using different approaches.
Make sure you have all the required dependencies installed:
pip install -r requirements.txt
pip install -r requirements-test.txtRun the simple test script directly:
python test_pose_detector_simple.pyThis will run basic functionality tests and error handling tests without requiring pytest.
Run the full test suite:
# Run all tests
pytest tests/
# Run with verbose output
pytest tests/ -v
# Run with coverage report
pytest tests/ --cov=src --cov-report=html
# Run specific test file
pytest tests/test_pose_detector.py
# Run specific test method
pytest tests/test_pose_detector.py::TestPoseDetector::test_initialization# Start Python REPL
python
# Import and test
from src.pose_detector import PoseDetector
import numpy as np
# Create detector
detector = PoseDetector()
# Test with sample frame
frame = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
result = detector.detect_pose(frame)
# Check results
print(f"Pose detected: {detector.is_pose_detected()}")
print(f"Frame shape: {result.shape}")
# Clean up
detector.release()- ✅ Initialization of MediaPipe pose detection
- ✅ Frame processing and validation
- ✅ Pose detection workflow
- ✅ Landmark coordinate extraction
- ✅ Running keypoints retrieval
- ✅ Pose detection status checking
- ✅ None frame handling
- ✅ Empty frame handling
- ✅ Invalid frame dimensions (2D, wrong channels)
- ✅ Invalid landmark IDs
- ✅ Graceful degradation when no pose detected
- ✅ Complete workflow from detection to keypoint extraction
- ✅ Resource cleanup and memory management
- ✅ MediaPipe integration
tests/
├── test_pose_detector.py # Comprehensive pytest tests
├── requirements-test.txt # Testing dependencies
└── test_pose_detector_simple.py # Simple test script
TESTING.md # This guide
- All assertions passed
- Functionality working as expected
- Test failed
- Check error messages for debugging
-
Import Errors
- Make sure you're in the project root directory
- Check that
src/is in your Python path
-
MediaPipe Errors
- Ensure MediaPipe is properly installed
- Check version compatibility
-
OpenCV Errors
- Verify OpenCV installation
- Check numpy array compatibility
For performance testing, you can create larger frames or process multiple frames:
# Performance test with larger frames
large_frame = np.random.randint(0, 255, (1080, 1920, 3), dtype=np.uint8)
detector = PoseDetector()
import time
start_time = time.time()
for _ in range(100):
result = detector.detect_pose(large_frame)
end_time = time.time()
print(f"Processed 100 frames in {end_time - start_time:.2f} seconds")
detector.release()To integrate testing into your development workflow:
- Pre-commit hooks: Run tests before each commit
- GitHub Actions: Automate testing on push/PR
- Local development: Run tests after each significant change
- Read error messages carefully - they often point to the exact issue
- Check dependencies - ensure all packages are installed
- Verify file paths - make sure you're in the correct directory
- Use verbose output -
pytest -vprovides more details - Run individual tests - isolate the failing test case
When adding new features to PoseDetector:
- Write tests first (TDD approach)
- Cover edge cases - test invalid inputs
- Test error conditions - ensure graceful failure
- Update this guide - document new testing approaches
Happy testing! 🧪✨