इसे छोड़कर कंटेंट पर जाएं
Invoke

Writing Tests

यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।

The default frontend is webv2, with unit and Chromium suites. Run commands from the repository root:

Terminal window
# Run the default frontend unit suite once.
make frontend-test

Install Chromium with pnpm exec playwright install chromium from invokeai/frontend/webv2 if needed. Read webv2/AGENTS.md for test ownership and browser verification rules.

The legacy frontend remains in invokeai/frontend/webv1. From that directory, run its separate suite with pnpm test:no-watch and its checks with pnpm lint.

We use pytest to run the backend python tests. (See pyproject.toml for the default pytest options.)

All tests are categorized as either ‘fast’ (no test annotation) or ‘slow’ (annotated with the @pytest.mark.slow decorator).

‘Fast’ tests are run to validate every PR, and are fast enough that they can be run routinely during development.

‘Slow’ tests are currently only run manually on an ad-hoc basis. In the future, they may be automated to run nightly. Most developers are only expected to run the ‘slow’ tests that directly relate to the feature(s) that they are working on.

As a rule of thumb, tests should be marked as ‘slow’ if there is a chance that they take >1s (e.g. on a CPU-only machine with slow internet connection). Common examples of slow tests are tests that depend on downloading a model, or running model inference.

Below are some common test commands:

Terminal window
# Run the fast tests from the repository root using the Makefile shortcut.
make test
# Run the fast tests. (This implicitly uses the configured default option: `-m "not slow"`.)
pytest tests/
# Equivalent command to run the fast tests.
pytest tests/ -m "not slow"
# Run the slow tests.
pytest tests/ -m "slow"
# Run the slow tests from a specific file.
pytest tests/path/to/slow_test.py -m "slow"
# Run all tests (fast and slow).
pytest tests -m ""

Most backend tests live in the tests/ directory. When adding a new backend test, prefer keeping it near the corresponding module area so related code and tests stay easy to find together.

Tests do not download models routinely, and there is no shared helper that installs one. Prefer small CPU fixtures built in the test. A test that needs a real model must be marked slow (excluded by default and in CI) and must not download large models unless it is run on purpose. Keep the total number of models the slow tests need low, re-use models other tests already need, and comment why a new one is required.

The Windows ARM64 job exercises the lockfile’s ARM64 dependency fork and is slow, so it runs in shards, each a disjoint set of test files (tests/sharding.py, balanced by the durations in tests/shard_durations.json). It runs, with every shard, for every change the Python test filter matches (the filter the platform matrix jobs use), on pull requests, in the merge queue and on pushes to main; always_run runs it unconditionally. A maintainer is meant to mark py3.12: windows-arm64 (not the individual shards) as a required check; once it is, the merge queue blocks on ARM64 for every change that runs the Python tests.

Every shard uploads the durations it measured, but only from a session that exited cleanly. To refresh the balance, download the shard-durations-* artifacts of a run on main or in the merge queue where every shard passed (artifacts of a fork’s pull request are written by that pull request’s code), and merge them into tests/shard_durations.json from the repository root. The merge updates the existing entries and drops files that no longer exist:

Terminal window
gh run download <run-id> --pattern 'shard-durations-*' --dir <dir>
uv run --no-sync python -m tests.sharding <dir>/*/*.json

--shard=K/4 reproduces CI’s shard only on Windows ARM64 with the same lockfile: some files skip themselves at import there (for example test_umap_import.py), and the partition depends on the set of collected files. Anything that narrows the collection (-k, --lf, paths) changes it as well. To reproduce a failure, run the failing test files named in the job log directly, without --shard.

To review test coverage, append --cov and the report formats you want to your pytest command:

Terminal window
pytest tests/ --cov --cov-report=term --cov-report=html --cov-report=xml

Test outcomes and coverage will be reported in the terminal. In addition, a more detailed report is created in both XML and HTML format in the ./coverage folder. The HTML output is particularly helpful in identifying untested statements where coverage should be improved. The HTML report can be viewed by opening ./coverage/html/index.html.

:::note HTML coverage report output example html-overview

html-detail :::