Kuzu Test Configuration¶
The amplihack test suite includes tests that import kuzu — a C++ graph database with a Python binding. In environments where kuzu is not installed (e.g., CI without cmake, containers), these tests should skip gracefully rather than hang or error.
This document explains the approved isolation mechanism and the root cause that was fixed.
Contents¶
- How kuzu tests skip gracefully
- Root cause: package shadowing bug
- Which test files are guarded
- Verify the skip works
- Related
How kuzu tests skip gracefully¶
Each kuzu-specific test file has pytest.importorskip("kuzu") near the top:
import pytest
pytest.importorskip("kuzu") # skips entire module if kuzu not installed
from src.amplihack.memory.backends.kuzu_backend import KuzuBackend
When kuzu is not installed, pytest.importorskip raises Skipped during collection, and the entire module is skipped cleanly — no error, no hang.
This is the standard pytest pattern for optional-dependency tests and requires no environment variables or conftest configuration.
Note: PR #3110, which proposed an
AMPLIHACK_SKIP_KUZU_TESTSenvironment variable guard inconftest.py, was rejected. Thepytest.importorskipapproach in individual files is simpler, more portable, and follows standard pytest conventions.
Root cause: package shadowing bug¶
The original hang was caused by tests/memory/kuzu/__init__.py existing.
How it happened:
tests/memory/kuzu/__init__.pymadetests/memory/kuzu/a Python package.- pytest's default (prepend) import mode added
tests/memory/tosys.pathwhen collecting files from that directory. import kuzuinkuzu_backend.pyresolved totests/memory/kuzu/(the test package) instead of the installed PyPIkuzupackage.- The test package had no
Databaseattribute →AttributeErrorat collection time, causing hangs.
The fix: tests/memory/kuzu/__init__.py and tests/memory/kuzu/indexing/__init__.py were deleted. Without __init__.py, pytest adds tests/memory/kuzu/ itself (not tests/memory/) to sys.path, and there is no kuzu package name to shadow there.
Which test files are guarded¶
All kuzu-specific test files carry pytest.importorskip("kuzu"):
| File | Notes |
|---|---|
tests/memory/backends/test_kuzu_session_isolation.py | Guard placed before module-level KuzuBackend import |
tests/memory/backends/test_kuzu_schema_redesign.py | |
tests/memory/backends/test_kuzu_code_schema.py | |
tests/memory/backends/test_kuzu_auto_linking.py | |
tests/memory/kuzu/test_kuzu_connector.py | |
tests/unit/memory/test_kuzu_retry.py |
The guard coverage is verified by tests/test_kuzu_skip_guard.py (WS4 tests).
Verify the skip works¶
When kuzu is installed, all tests collect and run normally:
To simulate a missing kuzu installation, temporarily rename the package and confirm the module is skipped (not errored):
pytest --collect-only -q tests/memory/backends/test_kuzu_schema_redesign.py
# With kuzu absent: "1 skipped" not "ERROR"
Collection time for all kuzu tests must be under 10 seconds:
Related¶
- conftest.py — Root pytest configuration (minimal, no kuzu-specific guards)
- pytest importorskip docs
- kuzu Python bindings — upstream library
- Ladybug Migration Guide —
kuzu_store→ladybug_storeupgrade
Note: The
KuzuGraphStoreclass (inamplihack.memory.ladybug_store) now importsladybugwith a fallback tokuzu. The backend-level test files listed above still testkuzu_backend.pywhich importskuzudirectly — those are separate from theKuzuGraphStoremigration.