Skip to content

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 are located in the tests/unit folder. They are written using the pytest framework.

  1. Create a Python virtual environment (recommended)

  2. Install the dependencies with the following command:

    Terminal window
    pip install ".[api,test]"
  3. 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 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.

  1. Create a Python virtual environment (recommended)

  2. Install the dependencies with the following command:

    Terminal window
    pip install ".[api,test]"
  3. 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
  4. 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"
}

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 statusUnit testsIntegration testse2e tests
DraftYes, without coverage or badge commitYesNo
Ready for reviewYes, with coverage and badge commitYesYes

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.