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.

Integración continua

Current test results can be found on GitHub Actions and coverage is reported on Codecov.

There are several jobs to verify different aspects:

  • Pruebas unitarias

  • 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 database connection. The example definition of that is in scripts/test-database:

# Simple way to configure test database from environment

# 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:

. scripts/test-database
./ci/run-migrate
./ci/run-test
./ci/run-docs

Puesta a prueba local

Para ejecutar un conjunto de pruebas localmente, utilice:

DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py test

Consejo

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 Configuración de base de datos para Weblate for setup instructions.

The weblate/settings_test.py is used in CI environment as well (see Integración continua) and can be tuned using environment variables:

# Simple way to configure test database from environment

# 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

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

También puede especificar que se ejecuten solo pruebas individuales:

DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py test weblate.gitexport

Consejo

The tests can also be executed inside developer docker container, see Ejecutar Weblate localmente en Docker.

Ver también

See Testing in Django for more info on running and writing tests for Django.