This document provides comprehensive information about testing the Claude Gemini MCP Slim project.
# Install dependencies
make install
# Run smoke test to verify setup
make test-smoke
# Run fast unit tests
make test-fast
# Run integration tests (sequential)
make test-integration
# Run all tests with coverage
make test-alltests/
├── conftest.py # Shared fixtures and configuration
├── unit/ # Unit tests (fast, isolated)
│ ├── __init__.py
│ └── test_basic_operations.py
├── integration/ # Integration tests (slower, real components)
│ ├── test_cli_fallback.py
│ ├── test_gemini_api_mocked.py
│ └── test_mcp_server_integration.py
└── e2e/ # End-to-end tests (full system)
└── test_full_workflow.py
make test-fast
# or
python3 scripts/run_tests.py fast- Runs in parallel using all CPU cores
- 10-second timeout per test
- No coverage collection for speed
- Ideal for development workflow
make test-integration
# or
python3 scripts/run_tests.py integration- Runs sequentially to avoid resource conflicts
- 30-second timeout per test
- Stops on first failure
- Proper resource isolation
make test-integration-parallel
# or
python3 scripts/run_tests.py integration-parallel- Limited parallel execution (2 workers)
- Better for stable integration tests
- Uses loadscope distribution
make test-all
# or
python3 scripts/run_tests.py all- Runs all tests with coverage report
- Generates HTML coverage report
- Requires 70% coverage to pass
make test-debug TEST_PATTERN=tests/integration/test_cli_fallback.py
# or
python3 scripts/run_tests.py debug --test-pattern="tests/integration/test_cli_fallback.py"- No parallel execution
- Detailed output and logging
- No output capture
- 60-second timeout
# Run specific test file
make test-specific TEST_PATTERN=tests/unit/test_basic_operations.py
# Run specific test class
make test-specific TEST_PATTERN=tests/unit/test_basic_operations.py::BasicTests
# Run specific test method
make test-specific TEST_PATTERN=tests/unit/test_basic_operations.py::BasicTests::test_addition
# Run tests with keyword matching
make test-specific TEST_PATTERN='-k sanitization'
# Run tests with markers
make test-specific TEST_PATTERN='-m "not slow"'[tool.pytest.ini_options]
addopts = [
"--timeout=30", # 30 second timeout per test
"--timeout-method=thread", # Thread-based timeout
"-n auto", # Auto-detect CPU cores
"--maxfail=5", # Stop after 5 failures
"--tb=short", # Short traceback format
]@pytest.mark.slow- Slow-running tests@pytest.mark.integration- Integration tests@pytest.mark.unit- Unit tests@pytest.mark.security- Security-focused tests@pytest.mark.timeout- Tests that should timeout
The project includes several mechanisms to prevent hanging tests:
- Global 30-second timeout per test
- Thread-based timeout method
- Configurable timeouts for different test types
- pytest-xdist for parallel execution
- Automatic CPU core detection
- Process isolation prevents deadlocks
- Proper fixture cleanup
- Mock object isolation
- Temporary workspace creation
- Environment reset between tests
- Patch cleanup
- Resource tracking
Solutions:
- Use sequential mode:
make test-integration - Check for infinite loops in test code
- Verify mock objects are properly configured
- Use debug mode for detailed output
Solutions:
- Use the session-scoped event loop fixture
- Ensure proper async/await patterns
- Check for event loop conflicts in parallel execution
Solutions:
- Use
resource_cleanupfixture - Ensure proper teardown in fixtures
- Check for unclosed files/processes
Solutions:
- Use
parallel_safe_mockfixture - Implement proper test isolation
- Avoid global state dependencies
# Unit tests without coverage
python3 -m pytest tests/unit/ --no-cov -n auto
# Integration tests without coverage
python3 -m pytest tests/integration/ --no-cov -n 1# Run tests related to specific files
make test-specific TEST_PATTERN=tests/unit/test_basic_operations.py# Skip slow tests
python3 -m pytest -m "not slow"
# Run only unit tests
python3 -m pytest -m unit- name: Run fast tests
run: make test-fast
- name: Run integration tests
run: make test-integration
- name: Run all tests with coverage
run: make test-all# Full CI pipeline
make ci
# Quick development check
make check
# Full validation
make validatemake test-debug TEST_PATTERN=tests/integration/test_cli_fallback.py::TestCLIFallbackSecurity::test_no_shell_injectionpython3 -m pytest tests/integration/ -vv --log-cli-level=DEBUG --capture=nopython3 -m pytest tests/integration/test_cli_fallback.py::TestCLIFallbackSecurity::test_no_shell_injection -vv- Use descriptive test names
- Keep tests focused and isolated
- Use appropriate fixtures
- Mock external dependencies
- Group related tests in classes
- Use proper test markers
- Maintain test independence
- Use parallel execution for unit tests
- Use sequential execution for integration tests
- Skip coverage collection during development
- Regularly run the full test suite
- Monitor test execution times
- Clean up test artifacts regularly
The testing infrastructure requires:
pytest>=7.4.0- Testing frameworkpytest-asyncio>=0.21.0- Async test supportpytest-xdist>=3.8.0- Parallel executionpytest-timeout>=2.4.0- Timeout managementpytest-cov>=4.1.0- Coverage reportingpytest-mock>=3.11.0- Mock utilities
Install all dependencies with:
make installFor additional help with test patterns:
make test-helpFor general help with available commands:
make help