Running tests: qgis-sdk test
qgis-sdk test [PYTEST_ARGS]... [--project PATH] [--target pure|qgis|desktop|server|web] [--qgis-prefix PATH] is a thin, environment-aware pytest runner (decision-8,
decision-7): it decides where pytest runs and forwards everything else.
Unknown arguments go to pytest unchanged (qgis-sdk test -x -k ping,
qgis-sdk test -- --lf), pytest’s output is pytest’s and its exit code is the
command’s. A plain pytest in the project keeps working: the generated
pyproject.toml loads the same plugin through
addopts = "-p qgis_sdk_tools.pytest_plugin".
| Target | Where pytest runs | Selection |
|---|---|---|
pure (default) |
this interpreter | -m "not qgis and not desktop and not server"; importing qgis, PyQt* or PySide* fails the test that did it |
qgis |
the located QGIS’s Python with its bindings on PYTHONPATH, headless by default |
-m qgis; the qgis_app fixture is a QgsApplication |
desktop |
pytest inside the QGIS Desktop binary, temporary profile | -m desktop; qgis_iface is the real iface, qgis_app the running application |
server |
the located QGIS’s Python with its server bindings, headless | -m server; qgis_app is a QgsApplication and qgis.server has to import |
web |
the project’s package manager (bun/pnpm/npm from the lockfile) |
run test in web/, i.e. the generated Vitest suite |
qgis_sdk_tools.pytest_plugin registers the qgis, desktop and server
markers, provides the fixtures, applies the pure-target import guard, refuses a
server run whose QGIS has no qgis.server (exit 1, naming the build that has
them) and fails a native target in which every selected test skipped (exit 1 with
the reason), so a required gate cannot pass by skipping. A native target whose QGIS cannot be found
exits 2 naming what was tried; nothing is downloaded. Temporary profiles and
the request file live under a per-run directory that is removed afterwards;
QT_QPA_PLATFORM, QTWEBENGINE_CHROMIUM_FLAGS and a placeholder DISPLAY
are set only when the shell has no display (DISPLAY/WAYLAND_DISPLAY
unset on Linux); an exported QT_QPA_PLATFORM wins.
QGIS is located the same way for test and dev (decision-14, in
qgis_sdk_tools.devtools.installs.find_qgis_install): --qgis-prefix, then
[tool.qgis-sdk] qgis-prefix in pyproject.toml, then QGIS_PREFIX_PATH,
then qgis on PATH, then the interpreter’s own prefix. An explicit answer
that lacks the bindings (share/qgis/python, apps/qgis*/python) is an
error, not a fall-through. plan_tests(...) / plan_dev(...) return the
process plan (argv, cwd, env, notes) without running it, which is what the
unit tests assert on; the commands print the notes to stderr before running.