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:
docker compose run --rm home make test
To run specific pytest files:
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
Task | Command |
---|---|
Run all linters | docker compose run --rm home make lint |
Lint JavaScript only | docker compose run --rm home npm run lint |
Lint Python only | docker compose run --rm home make lint |
Run pre-commit hooks | pre-commit run --all-files |
Bypass pre-commit | git commit --no-verify |
Setting Up Pre-commit Hooks (Recommended)
For the best development experience, set up pre-commit hooks to automatically check your code before each commit:
Install pre-commit:
bash# Using pip pip install pre-commit # Or using Homebrew (macOS) brew install pre-commit
Install git hooks:
bashpre-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):
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.