pyai.docs

AI Engineering › 14 of 14

Errors, Logging & Testing

Production habits that keep pipelines reliable.

python
import logging
log = logging.getLogger(__name__)

try:
    data = load(path)
except FileNotFoundError as e:
    log.error("missing data: %s", e)
    raise

# test_metrics.py — run with: pytest
def test_accuracy():
    assert accuracy([1, 0], [1, 1]) == 0.5
  • Use virtual envs (venv / uv)
  • Pin dependencies
  • Seed randomness for reproducibility

⚡ Quick check

  • ✓ Catch specific exceptions
  • ✓ logging over print
  • ✓ pytest + assert