Skip to content

Testing Guide

This document provides comprehensive information about running and writing tests for the Open Library project, including automated tests, linting, and manual testing procedures.

Running Automated Tests

Run all JavaScript and Python unit tests in a Docker container:

bash
docker compose run --rm home make test

To run specific pytest files:

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

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 JavaScript onlydocker compose run --rm home npm run lint
Lint Python onlydocker compose run --rm home make lint
Run pre-commit hookspre-commit run --all-files
Bypass pre-commitgit commit --no-verify

For the best development experience, set up pre-commit hooks to automatically check your code before each commit:

  1. Install pre-commit:

    bash
    # Using pip
    pip install pre-commit
    
    # Or using Homebrew (macOS)
    brew install pre-commit
  2. Install git hooks:

    bash
    pre-commit install

After setup, your code will be automatically checked when you run git commit.

Troubleshooting

Python Version Mismatch

If you encounter version-related errors, ensure your Python version matches the one specified in .pre-commit-config.yaml. The error message might be: failed to find interpreter for Builtin discover of python_spec='python3.11'.

Common solutions:

  • Use pyenv to manage Python versions
  • Create a virtual environment with the correct Python version
  • Update your system Python if possible

Skipping Hooks

To commit without running hooks (use sparingly):

bash
git commit --no-verify -m "Your commit message"

The primary use case for skipping hooks is if you want to commit your code knowing it has issues just to save your work, or if you're submitting a quick proof of concept.