Factory.ai

Open-Source Wikis

/

Stable Diffusion WebUI

/

How to contribute

/

Testing

AUTOMATIC1111/stable-diffusion-webui

Testing

The repository ships a small functional test suite that exercises the FastAPI surface. There are no UI tests and no unit tests for individual modules.

What's tested

The tests live in test/:

File What it checks
test/test_txt2img.py POST /sdapi/v1/txt2img with default and edited parameters; checks that an image is returned.
test/test_img2img.py POST /sdapi/v1/img2img with an inline base64 image.
test/test_extras.py POST /sdapi/v1/extra-single-image.
test/test_face_restorers.py The face-restoration codepath through the API.
test/test_torch_utils.py modules.torch_utils.float64() — the only pure-Python unit test in the tree.
test/test_utils.py GET /sdapi/v1/options, samplers, models, etc. — the read-only API.

The tests share a pytest base_url of http://127.0.0.1:7860 (configured in pyproject.toml under [tool.pytest.ini_options]) and use pytest-base-url --verify-base-url to wait for the server before running.

Running the test suite

You need a running webui server. The CI workflow (.github/workflows/run_tests.yaml) shows the canonical incantation, which works on any platform:

# Install test dependencies
pip install -r requirements-test.txt

# Start the server in CPU mode in the background
python launch.py \
    --skip-prepare-environment \
    --skip-torch-cuda-test \
    --test-server \
    --do-not-download-clip \
    --no-half \
    --disable-opt-split-attention \
    --use-cpu all \
    --api-server-stop &

# Wait until the server responds
python -c "import requests, time
while True:
    try: requests.get('http://127.0.0.1:7860/'); break
    except Exception: time.sleep(1)"

# Run the tests
python -m pytest -vv --verify-base-url test/

# Stop the server
curl -X POST http://127.0.0.1:7860/sdapi/v1/server-stop

The flags exist for a reason:

  • --test-server — sets cmd_opts.test_server = True, which makes modules/launch_utils.py configure_for_tests() substitute a tiny stub checkpoint for the default SD 1.5 download. Tests run in seconds, not minutes.
  • --api-server-stop — registers /sdapi/v1/server-stop so the test runner can shut the server down after the suite finishes.
  • --use-cpu all — runs everything on CPU. GitHub-hosted runners do not have GPUs.
  • --no-half and --disable-opt-split-attention — keep CPU inference deterministic and avoid CUDA-only attention paths.

Coverage

The CI workflow also collects coverage:

python -m coverage run --data-file=.coverage.server launch.py ...
python -m coverage combine .coverage*
python -m coverage report -i
python -m coverage html -i

The htmlcov/ artifact is uploaded by CI but coverage thresholds are not enforced. The current line coverage is roughly in the low-double-digit percentage range — the API surface is covered, the UI and most processing internals are not.

Writing a new test

API-level tests are the only style currently in use. Mirror the structure of an existing file:

# test/test_my_endpoint.py
import requests

def test_my_endpoint(base_url):
    r = requests.post(f"{base_url}/sdapi/v1/my-endpoint", json={"foo": "bar"})
    assert r.status_code == 200
    assert "image" in r.json()

base_url is provided by pytest-base-url. The fixture conftest.py (test/conftest.py) only handles output paths.

If you genuinely need to unit-test pure logic (no GPU, no Gradio, no FastAPI), add it next to test_torch_utils.py. Such tests run regardless of the server.

Local quick check

For day-to-day development, a fast smoke test is to start the test server and run a single endpoint:

python launch.py --skip-torch-cuda-test --test-server --use-cpu all --no-half &
pytest -vv test/test_utils.py

This validates the boot path and /sdapi/v1/options without a full image generation, which on CPU still takes ~30–60 s per image.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Testing – Stable Diffusion WebUI wiki | Factory