This directory contains tests for the OpenAPI MCP Server project.
The tests are organized by module:
-
tests/api/: Tests for API-related modulestest_config.py: Tests for API configuration handlingtest_discovery.py: Tests for the API discovery module
-
tests/prompts/: Tests for prompt-related modulestest_instructions.py: Tests for dynamic instruction generationtest_operation_instructions.py: Tests for operation-specific promptstest_enhanced_instructions.py: Tests for enhanced API documentation
-
tests/utils/: Tests for utility modulestest_cache_provider.py: Tests for the cache provider moduletest_http_client.py: Tests for the HTTP client utilitiestest_metrics_provider.py: Tests for the metrics provider moduletest_metrics_provider_prometheus.py: Tests for the Prometheus metrics provider (skipped if prometheus_client not installed)test_metrics_provider_decorators.py: Tests for the metrics provider decoratorstest_openapi_validator.py: Tests for the OpenAPI validation utilities
-
tests/test_init.py: Tests for module initialization -
tests/test_main.py: Tests for the main entry point -
tests/test_server.py: Tests for the server creation and configuration
To run the tests, use pytest:
# Install test dependencies
pip install "awslabs.openapi-mcp-server[test]"
# Run all tests
pytest
# Run tests with coverage
pytest --cov=awslabs
# Run specific test file
pytest tests/utils/test_cache_provider.py
# Run tests with verbose output
pytest -vThe tests aim to cover:
-
Unit Tests: Testing individual components in isolation
- Configuration handling
- OpenAPI spec loading and validation
- Caching mechanisms
- Metrics collection
- HTTP client functionality
- API discovery tools
- Prompt generation utilities
-
Integration Tests: Testing components working together
- Server creation and configuration
- API mounting and tool registration
- Authentication handling
- Dynamic prompt generation
- Operation-specific prompts
Some tests can be influenced by environment variables:
ENABLE_CACHETOOLS=true: Test with cachetools integrationENABLE_PROMETHEUS=true: Test with Prometheus metrics (requires prometheus_client package)ENABLE_TENACITY=true: Test with tenacity retry logicENABLE_OPENAPI_CORE=true: Test with openapi-core validationENABLE_OPERATION_PROMPTS=true: Test with operation-specific prompts
The tests use mocking to isolate components:
- External HTTP requests are mocked using
httpxmocks - File operations are mocked using
mock_open - Environment variables are temporarily set and restored
- Async functions are tested using
pytest.mark.asyncioandAsyncMock - MCP server functionality is mocked using
MagicMock
When adding new tests:
- Follow the existing module structure
- Use appropriate mocking to avoid external dependencies
- Test both success and failure paths
- Include tests for edge cases
- Ensure tests are isolated and don't depend on external state
- For prompt tests, verify both content generation and registration