Skip to content

Testing Guide

This guide covers running and writing tests for the Open Library project.

Running Tests

When to Use What

ScenarioCommand
Full test suite (before opening a PR)make test
Python-only changespytest
JavaScript-only changesnpm run test
Type checking Pythonmake mypy

All commands below run inside docker compose run --rm home.

Run All Tests

Runs the full test suite — Python tests, JavaScript tests, and type checks. Use this before opening a PR or when your changes touch multiple parts of the codebase.

bash
docker compose run --rm home make test

Run Python Tests Only

Use pytest when your changes only affect Python files. This is faster than running the full suite.

bash
docker compose run --rm home pytest

Run a specific test file:

bash
docker compose run --rm home pytest openlibrary/plugins/importapi/tests/test_import_validator.py

Run tests matching a pattern:

bash
docker compose run --rm home pytest -k "test_name_pattern"

Run JavaScript Tests

Use npm run test when your changes only affect JavaScript or CSS files.

bash
docker compose run --rm home npm run test

Run Type Checks

Runs mypy type checking on the Python codebase.

bash
docker compose run --rm home make mypy

Linting

Open Library uses automated linting to maintain code quality and consistency. The CI server automatically checks all pull requests for linting issues. To save time, you can run these checks locally before pushing your changes.

Quick Reference

TaskCommand
Run all lintersdocker compose run --rm home make lint
Lint JavaScriptdocker compose run --rm home npm run lint
Lint Pythondocker compose run --rm home make lint
Run pre-commit hookspre-commit run --all-files
Bypass pre-commitgit commit --no-verify

For details on setting up and troubleshooting pre-commit, see the Pre-Commit Guide.

Manual Testing

When testing changes locally, use these pages to verify your work. All URLs assume a local dev server at localhost:8080.

Having trouble accessing a page?

If you can't reach a page due to permissions, missing data, or anything else, reach out to us on Slack and we'll help you get set up.

Core Record Pages

PageURLNotes
Book (edition)/books/OL{ID}MIndividual edition with cover, metadata, borrow/read options
Work/works/OL{ID}WGroups all editions of a book
Author/authors/OL{ID}ABio, photo, and list of works
Subject/subjects/{name}Browse books by topic, e.g. /subjects/fiction
Tag/tag/{name}View a tag page
Add Tag/tag/addCreate a new tag

Search & Discovery

PageURLNotes
Search/search?q={query}Main book search
Search (JSON)/search.json?q={query}API endpoint for search results
Trending/trendingPopular books
Homepage/Featured content and carousels

User & Reading Log

PageURLNotes
Login/account/login
Register/account/create
Profile/people/{username}Public user profile
My Books/people/{username}/booksReading log overview
Want to Read/people/{username}/books/want-to-read
Currently Reading/people/{username}/books/currently-reading
Already Read/people/{username}/books/already-read
Lists/people/{username}/listsUser-created lists
Loans/account/loansActive loans (logged-in user)

Editing & Imports

PageURLNotes
Add a Book/books/addManual book creation form
Edit Edition/books/OL{ID}M/editEdit an existing edition
Edit Work/works/OL{ID}W/editEdit an existing work
ISBN Lookup/isbn/{isbn}Lookup or import by ISBN
Import API/api/importJSON import endpoint

Info Pages

PageURLNotes
About/about
Help/help
Recent Changes/recentchangesRecent edits across the site
Stats/statsSite-wide statistics
Lending Stats/stats/lending

API Endpoints

EndpointNotes
/api/booksBooks API
/api/searchSearch API
/api/importImport API
/api/import/iaArchive.org item import
/search.jsonSearch results as JSON

TIP

URL ID formats: OL + number + type letter — A (author), W (work), M (edition). For example, OL1234W is a work and OL5678M is an edition.