Skip to content

Testing Quick Start

crocodilestick edited this page Oct 24, 2025 · 2 revisions

Testing Quick Start Guide

Get up and running with CWA tests in 5 minutes!

πŸš€ TL;DR

# Run the interactive test runner
./run_tests.sh

# Choose option 5 for a quick test

That's it! The script handles everything else.

πŸ“‹ Prerequisites

You need:

  • βœ… Docker installed and running
  • βœ… Python 3.10+ (3.13 recommended)
  • βœ… Bash shell

On macOS/Linux:

# Check Docker
docker --version

# Check Python (3.10 minimum, 3.13 recommended)
python3 --version

On Windows (WSL2):

# Install WSL2 first, then:
docker --version
python3 --version

🎯 Quick Test (10 Seconds)

Verify everything works:

# Run smoke tests (fast, no Docker needed for most)
pytest tests/smoke/ -v

Expected output:

tests/smoke/test_smoke.py::test_python_version PASSED
tests/smoke/test_smoke.py::test_flask_app_can_be_imported PASSED
tests/smoke/test_smoke.py::test_cwa_db_can_be_imported PASSED
...
10 passed, 9 skipped in 2.15s βœ…

Note: Some tests will skip if you're not inside a Docker container - this is normal!

🎨 Interactive Test Runner

The easiest way to run tests:

1. Launch the Menu

./run_tests.sh

2. You'll See This Menu

╔════════════════════════════════════════════════════════════════╗
β•‘         CALIBRE-WEB AUTOMATED - TEST RUNNER                    β•‘
╠════════════════════════════════════════════════════════════════╣
β•‘ Environment: host                                              β•‘
β•‘ Python: 3.13.0                                                 β•‘
β•‘ Docker: Available βœ“                                            β•‘
╠════════════════════════════════════════════════════════════════╣
β•‘ TEST SUITE OPTIONS                                             β•‘
╠════════════════════════════════════════════════════════════════╣
β•‘ 1) Integration Tests (Bind Mount Mode)                        β•‘
β•‘    β†’ Standard mode for local testing (20 tests, ~3-4 min)     β•‘
β•‘                                                                β•‘
β•‘ 2) Integration Tests (Docker Volume Mode)                     β•‘
β•‘    β†’ For dev containers/DinD (19 tests, ~3-4 min)             β•‘
β•‘                                                                β•‘
β•‘ 3) Docker Startup Tests                                       β•‘
β•‘    β†’ Container health checks (9 tests, ~1 min)                β•‘
β•‘                                                                β•‘
β•‘ 4) All Tests                                                  β•‘
β•‘    β†’ Complete test suite (~5-7 min)                            β•‘
β•‘                                                                β•‘
β•‘ 5) Quick Test                                                 β•‘
β•‘    β†’ Fast verification (1 test, ~30 sec)                       β•‘
β•‘                                                                β•‘
β•‘ 6) Custom Test Selection                                      β•‘
β•‘    β†’ Run specific tests/patterns                               β•‘
β•‘                                                                β•‘
β•‘ 7) Show Info                                                  β•‘
β•‘    β†’ Test environment & documentation                          β•‘
β•‘                                                                β•‘
β•‘ q) Quit                                                       β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Enter your choice [1-7, q]:

3. Choose an Option

First time? Choose option 5 for a quick test.

Want full test suite? Choose option 1 (standard mode).

In a dev container? Choose option 2 (it may auto-select this).

πŸ”§ Manual Testing

If you prefer command-line:

Run Specific Test Categories

# Smoke tests (30 seconds)
pytest tests/smoke/ -v

# Unit tests (2 minutes)
pytest tests/unit/ -v

# Docker tests (1 minute)
pytest tests/docker/ -v

# Integration tests (3-4 minutes)
pytest tests/integration/ -v

# Everything (5-7 minutes)
pytest tests/ -v

Run Specific Tests

# Single test file
pytest tests/unit/test_cwa_db.py -v

# Single test function
pytest tests/smoke/test_smoke.py::test_python_version -v

# Tests matching a pattern
pytest -k "database" -v

# Tests in parallel (faster)
pytest tests/unit/ -n auto

πŸ‹ Testing in Dev Containers

If you're running tests inside a Docker container (Docker-in-Docker):

# Set environment variable
export USE_DOCKER_VOLUMES=true

# Run tests
pytest tests/integration/ -v

Or use the interactive runner (it auto-detects):

./run_tests.sh
# It will show "Environment: docker" and auto-select volume mode

πŸ“Š Understanding Results

Success βœ…

tests/integration/test_ingest_pipeline.py::test_ingest_epub_already_target_format PASSED

Failure ❌

tests/integration/test_ingest_pipeline.py::test_some_feature FAILED

Check the error message for details.

Skipped ⏭️

tests/integration/test_cwa_db_tracks_import SKIPPED (requires config volume)

This is expected in Docker volume mode.

Test Count

20 passed, 1 skipped in 187.45s
  • 20 passed - Tests ran successfully
  • 1 skipped - Test was intentionally skipped
  • 187.45s - Total duration (~3 minutes)

πŸŽ“ Next Steps

Learn More

Once you're comfortable with basic testing:

  1. Running Tests - All execution modes explained
  2. Writing Tests - Contribute your own tests
  3. Docker-in-Docker Mode - Advanced DinD usage

Install Test Dependencies

For development:

pip install -r requirements-dev.txt

This installs:

  • pytest (test runner)
  • pytest-flask (Flask testing)
  • pytest-timeout (prevent hanging)
  • pytest-mock (mocking utilities)
  • faker (test data generation)

View Coverage Reports

See which code is tested:

# Generate HTML coverage report
pytest --cov=cps --cov=scripts --cov-report=html

# Open in browser
open htmlcov/index.html  # macOS
xdg-open htmlcov/index.html  # Linux

πŸ› Troubleshooting

"Docker is required but not found"

Fix: Install Docker Desktop

"pytest: command not found"

Fix: Install test dependencies

pip install pytest
# Or install all dev dependencies:
pip install -r requirements-dev.txt

"Permission denied" when running tests

Fix: Make test runner executable

chmod +x run_tests.sh

Tests are very slow

First run? Docker needs to download images (~1-2 GB). This happens once.

Subsequent runs should be much faster (3-4 minutes for integration tests).

Speed up tests:

# Run in parallel
pytest tests/unit/ -n auto

# Run only fast tests
pytest -m "not slow" tests/

"Container failed to start"

Fix: Check Docker is running

docker ps

If Docker isn't running, start Docker Desktop.

πŸ’‘ Pro Tips

1. Quick Iteration

While developing, use quick tests:

# Test just what you're working on
pytest tests/unit/test_cwa_db.py::test_specific_function -v

2. Watch Mode

Auto-run tests when files change:

pip install pytest-watch
ptw tests/unit/

3. Stop on First Failure

Useful when debugging:

pytest tests/ -x  # Stop at first failure
pytest tests/ -vv  # Extra verbose output

4. Re-run Failed Tests

After fixing a bug:

pytest --lf  # Run last failed tests only

5. Use the Interactive Runner

Seriously, it's easier:

./run_tests.sh

βœ… Checklist

Before submitting code:

  • Run smoke tests: pytest tests/smoke/ -v
  • Run relevant unit tests
  • Run integration tests if changing workflows
  • All tests pass βœ…
  • No new errors or warnings

🀝 Getting Help


You're ready to go! πŸŽ‰

Start with the interactive test runner (./run_tests.sh) and explore from there.

Clone this wiki locally