Testing Reference
Testing Reference
Section titled “Testing Reference”Complete reference for the IDX API pytest testing framework.
Available Commands
Section titled “Available Commands”The Makefile provides several targets for different testing scenarios:
Test Execution
Section titled “Test Execution”| Command | Description | Use Case |
|---|---|---|
make test | Run all tests with coverage | Default test run |
make test-fast | Run tests without coverage | Quick iteration during development |
make test-html | Generate HTML reports | Full reports with coverage |
make test-watch | Auto-run on file changes | Active development |
Filtered Tests
Section titled “Filtered Tests”| Command | Description |
|---|---|
make test-auth | Authentication tests only |
make test-unit | Unit tests in tests/unit/ |
make test-integration | Integration tests |
Documentation
Section titled “Documentation”| Command | Description |
|---|---|
make publish-docs | Copy reports to docs site |
make test-publish | Run tests + publish reports |
Test Structure
Section titled “Test Structure”idx-api/├── tests/│ ├── conftest.py # Shared fixtures│ ├── test_health.py # Health check tests│ ├── test_auth.py # Authentication tests│ ├── test_agents.py # Agent CRUD tests│ ├── unit/ # Unit tests (isolated)│ └── integration/ # Integration tests├── reports/│ ├── html/│ │ └── report.html # pytest HTML report│ └── coverage/│ └── index.html # Coverage report└── MakefileTest Markers
Section titled “Test Markers”Use pytest markers to categorize tests:
import pytest
@pytest.mark.authdef test_api_key_validation(): """Tests marked with @pytest.mark.auth""" pass
@pytest.mark.integrationdef test_database_operations(): """Tests that require full stack""" pass
@pytest.mark.slowdef test_embedding_generation(): """Tests that take longer to run""" passRun specific markers:
uv run pytest -m auth # Only auth testsuv run pytest -m "not slow" # Skip slow testsTest Fixtures
Section titled “Test Fixtures”The conftest.py file provides shared fixtures for all tests:
@pytest.fixturedef db_session(): """Create isolated test database session.""" engine = create_engine("sqlite:///:memory:") Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() yield session session.close()@pytest.fixturedef client(db_session): """FastAPI test client with database override.""" app.dependency_overrides[get_db] = lambda: db_session with TestClient(app) as c: yield c app.dependency_overrides.clear()@pytest.fixturedef admin_headers(db_session): """Headers with admin API key.""" api_key = create_test_api_key(db_session, role="admin") return {"X-API-Key": api_key}Test Configuration
Section titled “Test Configuration”Tests use pytest with the following plugins:
- pytest-asyncio - Async test support for FastAPI
- pytest-html - HTML report generation
- pytest-cov - Coverage measurement
Configuration in pyproject.toml:
[tool.pytest.ini_options]asyncio_mode = "auto"testpaths = ["tests"]Docker Commands
Section titled “Docker Commands”From the project root:
# Run tests in Docker containermake test-docker
# Run tests and publish to docs sitemake docs-publish
# Build docs image with embedded reportsmake docs-buildDocker Compose Services
Section titled “Docker Compose Services”The idx-api-test service runs tests in an isolated container:
# Run tests with the test profiledocker compose --profile test run --rm idx-api-test
# View test reports in docs dev serverdocker compose --profile dev up idx-docs-dev# Reports available at: https://help.{DOMAIN}/reports/tests/report.htmlVolume Sharing
Section titled “Volume Sharing”Test reports are stored in a Docker volume called test-reports:
- idx-api-test: Writes reports to
/app/reports→ volume - idx-docs-dev: Mounts volume at
/app/public/reports(read-only)
This allows the docs dev server to serve the latest reports without rebuilding.