Weblate 測試套件與連續整合¶
測試套件存在於多數目前代碼,通過為任何新的功能新增測試情況來擴大覆蓋範圍,並確認其正常工作。
連續整合¶
Current test results can be found on GitHub Actions and coverage is reported on Codecov.
有幾項工作來確認不同的方面:
單元測試
文件建置與外部連結
來自所有支援的發佈版本的合併測試
代碼整理
設定確認(確保產生的 dist 文件不遺失任何內容,並可以測試)
CI 的組態在 .github/workflows
目錄中。它重度使用了 ci
目錄中的幫助腳本。腳本還可以手動執行,但它們需要一些環境變量,多數用來定義 Django 設定要使用的文件和資料庫連接。它的示例定義在 scripts/test-database
中:
# 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
簡單的執行看起來可以像這樣:
. scripts/test-database.sh
./ci/run-migrate
./ci/run-test
./ci/run-docs
本地測試¶
Before running test, please ensure test dependencies are installed. This can be done by pip install -e .[test]
.
Testing using pytest¶
執行測試前,應該收集靜態文件,因為一些測試在出現時相依於它們:
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
Testing using Django¶
Alternatively, Django built-in tests should also work:
DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py test
提示
您會需要使用資料庫(PostgreSQL)伺服器來檢測。 Django 預設新建另外的資料庫,以 test_
前綴來執行測試,因此在您的設定組態使用 weblate
的情況下,測試會使用 test_weblate
資料庫。設定的指示請參見 Weblate 的資料庫設定。
weblate/settings_test.py
也用在 CI 環境中(請參見 連續整合),並且可以使用環境變量調整:
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
執行測試前,應該收集靜態文件,因為一些測試在出現時相依於它們:
DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py collectstatic
您也可以指定要執行的各自測試:
DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py test weblate.gitexport
提示
測試也可以在開發者 docker 容器內執行,請參見 在 Docker 中本地執行 Weblate。
也參考
執行並為 Django寫測試的更多資訊請參見 Testing in Django。