This guide explains how to set up and run tests for the MCP Context Forge project.
- Python 3.10 or higher
- virtualenv or venv (for virtual environment management)
- Make (for running Makefile commands)
First, create a virtual environment and install the project's development dependencies:
make venv # Create a virtual environment
make install # Install the project with development dependencies
To run all tests, simply use:
make test
This will:
- Create a virtual environment if it doesn't exist
- Install required testing dependencies (pytest, pytest-asyncio, pytest-cov)
- Run the pytest suite with verbose output
You can run specific tests by specifying the file or directory:
# Activate the virtual environment
source ~/.venv/mcpgateway/bin/activate
# Run a specific test file
python3 -m pytest tests/unit/mcpgateway/test_config.py -v
# Run a specific test class
python3 -m pytest tests/unit/mcpgateway/validation/test_jsonrpc.py::TestJSONRPCValidation -v
# Run a specific test method
python3 -m pytest tests/unit/mcpgateway/validation/test_jsonrpc.py::TestJSONRPCValidation::test_validate_valid_request -v
To test code examples from the README:
make pytest-examples
To run tests with coverage reporting:
# Activate the virtual environment
source ~/.venv/mcpgateway/bin/activate
# Run tests with coverage
python3 -m pytest --cov=mcpgateway tests/
# Generate a coverage report
python3 -m pytest --cov=mcpgateway --cov-report=html tests/
The HTML coverage report will be available in the htmlcov
directory.
When creating new tests, follow these guidelines:
- Place test files in the appropriate directory under
tests/unit/
- Use the naming convention
test_*.py
for test files - Use pytest fixtures from
conftest.py
where applicable - Use
@pytest.mark.asyncio
decorator for asynchronous tests
The project is configured to run tests automatically in CI/CD pipelines. When committing changes, ensure all tests pass locally first:
make test
If you encounter issues with running tests:
- Check that you're using the virtual environment with the correct dependencies
- Verify that your Python version is compatible (Python 3.10+)
- Try recreating the virtual environment:
make clean && make venv && make install
- Check for any error messages during dependency installation