Skip to content

Tests

The tests live in tests/ and run with pytest (in the dev dependency group, installed by uv sync). There are two kinds:

Folder Needs
Unit tests tests/unit/ Nothing. Pure logic, and providers driven with mocked clients
Integration tests tests/integration/ A throwaway Postgres database with pgvector

No test calls a real API, needs an API key or downloads a model.

Unit tests

uv run pytest tests/unit -q

They cover chunking and splitting, page-furniture removal, contextual chunk contexts, metadata filters, retrieval helpers (fusion, MMR, small-to-big), the web and S3 sources, every embedding, reranker and LLM provider (with mocked HTTP clients), the evaluation metrics, the extractor comparison script and the OpenAPI schema.

Most provider tests build the real provider class around a mocked client, so they fail when the provider's package is missing: install the extras they use. CI installs these (the TEST_EXTRAS of the workflow):

uv sync --extra openai --extra anthropic --extra bedrock --extra cohere \
        --extra ollama --extra mistral --extra gemini --extra voyage \
        --extra huggingface --extra fastembed --extra s3

Two groups are skipped when their package is not installed instead:

  • The Docling tests, without the docling extra.
  • The embedded vector DB tests (test_vectordb_with_vectors.py), per backend: Qdrant (always installed), Chroma, LanceDB, FAISS and Milvus Lite. Add --extra chroma --extra lancedb --extra faiss --extra milvus to run them all.

Integration tests

They run the real API (FastAPI's TestClient) against Postgres: uploads, processing, retrieval in every mode, hybrid search, small-to-big, reranking, reindexing, and web and S3 imports (a mock website and a fake S3 client).

Point them at a throwaway database with PAGELORE_TEST_DATABASE_URL:

export PAGELORE_TEST_DATABASE_URL=postgresql+psycopg://pagelore:pagelore@localhost:5432/pagelore_test
uv run pytest tests -q

Use a database you can lose

The tests migrate the database with Alembic and truncate every table before each test. To protect real data, they refuse to run unless the database name contains test. Without the variable, the integration tests are skipped.

One way to get a database, with the same image as the compose file:

docker run -d --name pagelore-test-db -p 5432:5432 \
  -e POSTGRES_USER=pagelore -e POSTGRES_PASSWORD=pagelore \
  -e POSTGRES_DB=pagelore_test pgvector/pgvector:0.8.7-pg18

(Use another host port, such as -p 5544:5432, if 5432 is taken, and put it in the URL.)

The app under test needs no other service:

  • Vector DB: an embedded Qdrant in a temporary folder.
  • Embeddings: a fake model that hashes words into a 64-number vector, so texts sharing words are close. It is fast and needs no download.
  • Reranker: a fake that scores by word overlap.
  • Files: a temporary folder per test. PDFs are written by a tiny built-in writer, not a library.

The fakes are in tests/fakes.py, and the fixtures (app_env, make_embedder, make_reranker, sample_files) in tests/conftest.py.

Useful commands

uv run pytest tests/unit/test_splitting.py -q     # one file
uv run pytest tests -q -k hybrid                  # tests whose name matches
uv run pytest tests -q -x --lf                    # stop at the first failure; rerun the last failures
uv run --python 3.10 pytest tests/unit -q         # another Python version

Writing tests

  • Put tests that need Postgres in tests/integration/ and use the app_env fixture. Everything else goes in tests/unit/.
  • Mock provider clients; never call a real service or download a model.
  • For an optional package that is heavy or platform-specific, skip when it is missing (as the Docling and vector DB tests do).