Weblate testsuite and continuous integration¶
Testsuites exist for most of the current code, increase coverage by adding testcases for any new functionality, and verify that it works.
Intégration continue¶
Weblate relies on GitHub Actions to run tests, build documentation, code linting, and other tasks to ensure code quality.
Codecov collects the code coverage information from the tests that were run.
There are several jobs to verify different aspects:
Unit tests
Documentation build and external links
Migration testing from all supported releases
Code linting
Setup verification (ensures that generated dist files do not miss anything and can be tested)
The configuration for the CI is in .github/workflows
directory. It
heavily uses helper scripts stored in ci
directory. The scripts can be
also executed manually, but they require several environment variables, mostly
defining Django settings file to use and test database connection. The example
definition of that is in scripts/test-database.sh
:
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Simple way to configure test database from environment
# shellcheck shell=sh
# Database backend to use postgresql / mysql / mariadb
export CI_DATABASE="${1:-postgresql}"
# Database server configuration
export CI_DB_USER=weblate
export CI_DB_PASSWORD=weblate
export CI_DB_HOST=127.0.0.1
# Django settings module to use
export DJANGO_SETTINGS_MODULE=weblate.settings_test
The simple execution can look like:
source scripts/test-database.sh
./ci/run-migrate
./ci/run-test
./ci/run-docs
Local testing of Weblate¶
Before running test, please ensure test dependencies are installed. This can be done by pip install -e .[test]
.
Testing using pytest¶
Prior to running tests you should collect static files as some tests rely on them being present:
DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py collectstatic
You can use pytest to run a testsuite locally:
pytest weblate
Running an individual test file:
pytest weblate/utils/tests/test_search.py
Indication
You will need a database (PostgreSQL) server to be used for tests. By
default Django creates separate database to run tests with test_
prefix,
so in case your settings is configured to use weblate
, the tests will
use test_weblate
database. See Configuration de la base de données pour Weblate for setup
instructions.
The weblate/settings_test.py
is used in CI environment as well (see
Intégration continue) and can be tuned using environment variables:
export CI_DATABASE=postgresql
export CI_DB_USER=weblate
export CI_DB_PASSWORD=weblate
export CI_DB_HOST=127.0.0.1
export CI_DB_PORT=60000
export DJANGO_SETTINGS_MODULE=weblate.settings_test
Indication
The tests can also be executed inside developer docker container, see Exécuter Weblate localement dans Docker.
Voir aussi
See Les tests dans Django for more info on running and writing tests for Django.
Local testing of Weblate modules¶
The tests are executed using py.test. First you need to install test requirements:
uv pip install -e '.[dev]'
You can then execute the testsuite in the repository checkout:
py.test