Run tests
OpenGateLLM uses a combination of unit, integration, and end-to-end tests to ensure the quality of the code.
Directoryapi/
Directorytests/
Directoryunit/
- …
Directoryintegration/
- …
Unit tests
Section titled “Unit tests”Unit tests are located in the tests/unit folder. They are written using the pytest framework.
-
Create a Python virtual environment (recommended)
-
Install the dependencies with the following command:
Terminal window pip install ".[api,test]" -
To run the tests, you can use the following command:
Terminal window pytest api/tests/unit --config-file=pyproject.toml --cov=./api --cov-report=html --cov-report=term-missing --cov-branch --cov-report=xml
Integration tests
Section titled “Integration tests”Integration tests are located in the tests/integration folder. They are written using the pytest framework and Docker compose to run the API and its dependencies in Docker containers.
-
Create a Python virtual environment (recommended)
-
Install the dependencies with the following command:
Terminal window pip install ".[api,test]" -
Start depencies services (postgres and redis) with the following command:
Terminal window docker compose --file compose.example.yml up --detach --quiet-pull --wait postgres redis -
To run the tests, you can use the following command:
Terminal window pytest api/tests/integration --config-file=pyproject.toml
To run the tests with VSCode, you can create a .vscode/settings.json file with the following content:
{ "python.terminal.activateEnvironment": true, "python.testing.pytestArgs": [ "api", "-s", "--config-file=pyproject.toml" ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "python.envFile": "${workspaceFolder}/.env" }Continuous integration
Section titled “Continuous integration”The Pull request and Main workflows run the Tests workflow on every pull request targeting main and on every push to main. It runs the unit and the integration tests in two parallel jobs, each one measuring its coverage. On main, the deployment to dev waits for the tests.
On every push to main, the Coverage workflow combines both measures with python-coverage-comment-action. It writes the total coverage to the run summary, and publishes the README badge and an HTML coverage report to the python-coverage-comment-action-data branch. That branch is managed by the action: do not protect it nor commit to it.