MockAPILoggerclass with comprehensive call tracking- Real-time console output with success/failure indicators (✅/❌)
- File-based logging in JSON Lines format
- Detailed call history with timestamps and metadata
- Total calls and success rates
- Method call counts
- Domain-specific operation tracking
- DNS record type analysis (A, MX, TXT, CNAME, etc.)
- Error tracking and reporting
- Environment variable control:
MOCK_API_LOGGING=true - Seamless pytest fixture integration
- Helper script:
test_with_logging.py - Live demo script:
test_logging_live.py
Successfully demonstrated:
- Basic Operations: 4 API calls, 100% success rate
- Error Handling: Proper error tracking and reporting
- Batch Operations: 12 API calls creating multiple record types
- 5 A records
- 3 MX records
- 3 TXT records
============================================================
MOCK API CALL SUMMARY
============================================================
Total Calls: 18
Unique Methods: 9
Success Rate: 100.0%
Errors: 0
Method Call Counts:
create_domain: 1
create_record: 10
delete_domain: 1
delete_record: 1
get_domain: 1
get_record: 1
list_domains: 1
list_records: 1
update_record: 1
Domain Operations:
example.com: 2 operations
newdomain.com: 1 operations
Record Types Created/Updated:
CNAME: 1
A: 5
MX: 3
TXT: 3
============================================================
# Environment variable
MOCK_API_LOGGING=true uv run pytest tests/test_client.py
# Using helper script
python test_with_logging.py tests/test_client.py✅ Mock API Call #1: list_domains
✅ Mock API Call #2: create_domain
Args: ('newsite.com', '192.168.1.100'), Kwargs: {}
✅ Mock API Call #3: list_records
Args: ('example.com',), Kwargs: {}
✅ Mock API Call #4: create_record
Args: ('example.com',), Kwargs: {'record_type': 'CNAME', 'name': 'www', 'data': 'example.com'}
- Debugging: Instantly see which API calls are made during tests
- Performance: Identify redundant or excessive API calls
- Coverage: Verify all API endpoints are tested
- Documentation: Understand test behavior and API usage patterns
- Integration Testing: Validate correct API call sequences
tests/mock_api_logger.py- Core logging implementationtest_with_logging.py- Helper script for easy test executiontest_logging_live.py- Live demonstration scriptdocs/mock_api_logging.md- Comprehensive documentation- Modified
tests/conftest.py- Integrated logging into fixtures
The mock API logging system is fully operational and ready for use:
- For debugging: Enable with
MOCK_API_LOGGING=truewhen tests fail - For analysis: Use file logging to analyze API usage patterns
- For documentation: Reference the console output to understand test behavior
- For optimization: Identify and eliminate redundant API calls
The implementation successfully provides visibility into mock API interactions, making test debugging and optimization significantly easier!