Local testing
Run a single job
When the handler runs outside Apipods, apipods.serverless.start() executes one job and exits. Pass the input on the command line:
$ python handler.py --test-input '{"input": {"prompt": "a lighthouse on a cliff at dusk", "steps": 4}}'
INFO apipods.serverless local test mode, job id: local-test
INFO apipods.serverless job local-test completed in 2104 ms
{"id": "local-test", "status": "COMPLETED", "output": {"path": "/volume/outputs/local-test.png", "seed": 1730299}}Without --test-input, the SDK looks for test_input.json next to the handler:
{
"input": {
"prompt": "a lighthouse on a cliff at dusk, 35mm photo",
"steps": 4
}
}Run a local API server
--serve starts an HTTP server that mimics the runtime API, so you can test clients against http://localhost:8000.
$ python handler.py --serve --port 8000
INFO apipods.serverless serving /run, /runsync, /status, /stream, /health on http://localhost:8000
$ curl -X POST http://localhost:8000/runsync \
-H "Content-Type: application/json" \
-d '{"input": {"prompt": "a lighthouse on a cliff at dusk"}}'The local server needs no API key and runs jobs one at a time unless you set concurrency_modifier. Point the SDKs at it with apipods.Client(run_base_url="http://localhost:8000").
Test the image with Docker
Before pushing, run the built image on a machine with an NVIDIA GPU (or on an Apipods pod) to catch missing dependencies and CUDA mismatches:
$ docker build --platform linux/amd64 -t sdxl-worker:dev ./worker
$ docker run --rm --gpus all -v "$PWD/volume:/volume" sdxl-worker:dev \
python -u handler.py --test-input '{"input": {"prompt": "test"}}'Unit tests
Handlers are plain functions, so you can test them directly with pytest. Guard the start call so importing the module does not start the worker:
from handler import handler
def test_rejects_missing_prompt():
result = handler({"id": "test-1", "input": {}})
assert result == {"error": "input.prompt is required"}if __name__ == "__main__":
apipods.serverless.start({"handler": handler})