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 Testing workflow selects jobs from the pull request state and the trigger type.
On a pull request targeting main (when api/** or the workflow file itself changes):
| PR status | Unit tests | Integration tests | e2e tests |
|---|---|---|---|
| Draft | Yes, without coverage or badge commit | Yes | No |
| Ready for review | Yes, with coverage and badge commit | Yes | Yes |
Manual runs (workflow_dispatch) and reusable calls (workflow_call) run all jobs. Unit tests include coverage. The coverage badge is committed only on a non-draft pull request targeting main.