Weblate テストスイートと継続的なインテグレーション

現在、ほぼすべてのコードにテストスイートがあります。新しい機能のテストケースを追加し、検査対象を増やして動作を検証します。

継続的なインテグレーション

Weblate はテストの実行、ドキュメントのビルド、コードの lint、その他の品質保証タスクを行うために GitHub Actions を利用しています。

Codecov は実行されたテストからコードカバレッジ情報を収集します。

さまざまな側面を検証するためのジョブ:

  • 単体テストおよび機能テストには pytest が使用されています。

  • ドキュメントのビルドおよび外部リンクの検証には Sphinx が使用されています。

  • コードの lint と品質保証には ruff と pylint が使用されています。

  • コードのセキュリティスキャンには CodeQL が使用されています。

  • Visual changes testing is utilizing Argos CI.

  • Code formatting using prek, a faster third-party reimplementation of the pre-commit framework.

  • 対応しているすべてのリリースからの移行テスト

  • Package builds, metadata, manifest, archive-content, and installation checks. The package lint tools are pinned in pyproject.toml and resolved in uv.lock; CI runs them with uv run --frozen.

  • Dependency review of pull requests.

GitHub rulesets protect main and stable. They require pull requests and passing status checks, including package build and lint checks and dependency review. The GitHub repository rules show the current required checks and permitted writers. Membership in the writer allowlist does not by itself bypass the pull-request or CI requirements. Repository administrators and organization owners have a separate bypass for maintainer operations.

CI の設定は、.github/workflows ディレクトリにあります。 ci ディレクトリに格納されているヘルパー スクリプトを頻繁に使用します。このスクリプトは手動でも実行できますが、使用する Django 設定ファイルとデータベース接続を設定するなど、環境変数の設定が必要です。確認すべき scripts/test-database.sh に記述された設定例:

The Selenium screenshot tests in weblate/trans/tests/test_selenium.py serve two purposes. They generate images for visual change testing in CI, and the same images are converted into documentation screenshots by make -C docs update-screenshots. Keep screenshot fixtures close to real rendered pages so CI catches UI regressions. When a screenshot includes volatile runtime data, prefer deterministic server-side test inputs over post-render DOM changes.

GitHub repository URLs in these screenshots use local Git transport rewrites. The shared Git fixture archive contains the ordinary test data and a separate, pinned demo revision, so repository discovery shows only demo content. Regenerate the archive with scripts/pack-test-data.sh; update its DEMO_REVISION when intentionally refreshing the demo data. Runtime tests do not fetch GitHub repositories or resolve their hostname. The TEST_REVISION pin controls the ordinary Git, Mercurial, and Subversion data independently.

Selenium tests that consume the standard demo can opt in with @reuse_demo_fixture from weblate/trans/tests/selenium_fixtures.py. Place it outside other method decorators. It restores committed database rows and the demo's working repositories before the test body, so call create_component() before creating additional components as usual. Create users and other test-specific data inside the test body; restoration replaces the database. GitHub transports and browser state remain isolated per test. Keep creation and empty-state tests undecorated so they continue to exercise the browser forms and generate their screenshots.

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

単純な実行例:

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

APT dependency cache

The shared APT installation action caches package indexes, downloaded packages, and the PGDG signing key in build/apt-cache/. Package selection, repository configuration, and Git pinning remain in ci/apt-install.

Installations first check that all needed packages are available locally, then install without downloads or an index update. Missing metadata, packages, or the signing key trigger online preparation with download retries. A failed local preflight does not run dpkg; installation errors after preflight remain fatal.

Cache keys include the Ubuntu version, architecture, installer hash, and UTC ISO week. Older weeks with the same compatibility prefix can be restored. Only the Python 3.14/latest test job and the ARM lock-update job save caches, and only on main. When a writer restores an older cache, it first installs offline, then tries to refresh indexes and download current dependencies. Failed refreshes do not fail a successful installation or publish a new cache; later runs retry. Refreshes happen on eligible workflow runs, without a separate schedule.

Cache service failures do not prevent online installation. Cold or incomplete caches still require upstream repositories, and runner image updates can change which packages are needed. An incomplete exact-key cache cannot be overwritten; online fallback remains necessary until a new weekly key is generated. Other APT installations outside this shared action are not covered by this cache.

OSS Scanner verification

The development Dockerfile shares its native dependencies and tooling between the development and scanner targets. VS Code, agent verification, and rundev.sh select development and retain mounted checkouts and separate Compose services. The final scanner target includes the checkout, locked Python dependencies, compiled assets, and local PostgreSQL and Valkey for verification without Internet access.

Build it from the repository root and run its offline smoke test:

docker build -f dev-docker/weblate-dev/Dockerfile -t weblate-oss-scanner .
docker run --rm --init --network none --user 0 --workdir /src --entrypoint bash \
    weblate-oss-scanner .oss-scanner/smoke

To run the complete backend suite, replace .oss-scanner/smoke with .oss-scanner/test. Append pytest selections or -n 0 for focused tests. No host mounts or external service containers are needed. The .github/workflows/rundev.yml workflow runs the focused smoke test on amd64, alongside the existing development-container checks.

The scanner uses Weblate の脅威モデル. The permissive test settings and local service authentication are test fixtures, not production deployment defaults.

Weblate のローカル テスト

For an isolated environment with dependencies and test services already configured, use the development container. Its CLI can run the same pytest and lint commands documented below in each Git worktree.

Before running tests, please ensure development dependencies are installed:

uv sync --all-extras --dev

pytest を使用したテスト

テストを実行する前に、静的ファイルの収集が必要です。テストによっては、静的ファイルの存在に依存しているためです。静的ファイルの収集方法:

DJANGO_SETTINGS_MODULE=weblate.settings_test uv run ./manage.py collectstatic --noinput

You can use pytest to run the test suite locally:

uv run pytest

Property-based tests using hypothesis run as part of the normal pytest suite. They check Markdown output safety, backup archive member paths, and SSH URL parsing with bounded generated inputs. Each property runs up to 100 generated examples deterministically, alongside explicit regression examples. Unexpected exceptions fail the test, and Hypothesis minimizes failing inputs. Add minimized inputs as explicit regression examples when fixing a failure. Timing deadlines are disabled to avoid failures caused by CI load.

個々のテストファイルの実行:

uv run pytest weblate/utils/tests/test_search.py

ヒント

テストには、使用するデータベース(PostgreSQL)サーバーが必要です。デフォルトでは、Django はテストを実行するために、接頭辞 test_ を付けた別のデータベースを作成します。そのため、weblate を使用するように設定している場合、テストには test_weblate データベースを使用します。設定方法については、Weblate のデータベース設定 を確認してください。

weblate/settings_test.py は CI 環境でも使用されます(参照: 継続的なインテグレーション)。環境変数を用いた設定方法:

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

ヒント

テストは、開発者の Docker コンテナ内でも実行できます。参照: Docker上でローカルに Weblate の実行。

参考

Django の実行と書き込みテストの詳細については、Django におけるテスト を確認してください。

Tests that repeatedly import the same component can inherit from ReusableComponentTestCase or ReusableViewTestCase in weblate/trans/tests/test_views.py. These bases build the initial user, project, component, and translations once per class in setUpTestData(). Override create_component() to select a repository fixture or file format, as with ComponentTestCase. For additional shared setup, override the build_fixture(cls, builder) class method, call super().build_fixture(builder), and use the builder's repository helpers and model instances.

Each test reloads its model instances and receives a restored copy of the working repositories, upstream repositories used during construction, and test Git configuration. Database changes are rolled back by Django. Clients, authentication, and application caches are initialized per test. Snapshots are temporary and local to each class and worker; extra components created within a test still use the normal component factories.

API tests inheriting APIBaseTest in weblate/api/tests.py use the same repository restoration. The API user and initial component, including its automatic glossary, are created once per class. Component construction callbacks run during this shared setup. API clients, credentials, and subclass setup such as screenshots and announcements are initialized per test.

Use the existing bases for TransactionTestCase and concurrency tests, or when component construction itself must run under a method-specific settings override. The reusable bases do not replay component construction signals or commit callbacks before each test.

Weblate モジュールのローカル テスト

The tests are executed using pytest. First you need to install development dependencies:

uv sync --all-extras --dev

そのあと、チェックアウトしたリポジトリでテストスイートを実行:

uv run pytest

テスト用リポジトリ

Weblate のテストスイートの多くは、テスト用リポジトリを使用します。テストスイート用のリポジトリは https://github.com/WeblateOrg/test で管理されています。scripts/pack-test-data.sh スクリプトを使用して、サポートされている各バージョン管理システム向けのリポジトリを含む tarball を生成します。この tarball は Weblate リポジトリ内に weblate/trans/tests/data/test-base-repo.git.tar、weblate/trans/tests/data/test-base-repo.hg.tar、weblate/trans/tests/data/test-base-repo.svn.tar として保存されます。

https://github.com/WeblateOrg/test リポジトリはリリース時にタグ付けされ、リリース時点で使用されたテストデータにアクセスできるようになっています。このスクリプトは、可能な限り再現性のある tarball を作成するように設計されています。