Skip to content

Improve test coverage (87% → 95%)#17

Merged
vladiant merged 2 commits into
mainfrom
extend-tests-coverage
Apr 4, 2026
Merged

Improve test coverage (87% → 95%)#17
vladiant merged 2 commits into
mainfrom
extend-tests-coverage

Conversation

@vladiant
Copy link
Copy Markdown
Collaborator

@vladiant vladiant commented Apr 4, 2026

Summary

Adds 44 new tests across 6 test files to close coverage gaps identified in the existing test suite. No production code changes — only new tests, version bump, and changelog update.

Changes

File Tests Covers
test_get_image.py 7 GetImageUseCase.execute() and get_file() — all branches including missing path for original/thumbnail
test_metrics_recording.py 5 _record_upload() and _record_duration() metrics paths, including error swallowing
test_health.py 5 _check_database failure, _check_storage missing directory, degraded health endpoint
test_executor_lifecycle.py 5 async_shutdown_executor (no-op, normal, timeout/force-cancel), executor singleton, shutdown_executor
test_observability.py 8 MetricsMiddleware (skip /health and /metrics, record normal/4xx/5xx), setup_tracing, setup_metrics, instrument_logging
test_config_and_main.py 14 Settings.database_url (including special char encoding), build_engine/build_session_factory, create_app ± CORS, _is_otel_enabled/_is_cors_enabled helpers, JSONFormatter with exc_info, InMemoryImageCache._evict_oldest on empty store

Coverage improvement

Metric Before After
Total coverage 87% 95%
Missing lines 148 52
Tests 216 260

Key modules improved

  • get_image.py: 83% → 100%
  • config.py: 95% → 100%
  • session.py: 71% → 100%
  • observability/middleware.py: 0% → 100%
  • observability/setup.py: 0% → 80%
  • pillow_processor.py: 82% → 100%
  • in_memory_cache.py: 98% → 100%
  • logging_config.py: 93% → 100%
  • health.py: 74% → 94%

Remaining uncovered (by design)

The remaining 52 lines are in OTel-gated branches in main.py (lifespan with OTel enabled, metrics endpoint) and DI factory wiring in dependencies.py — these require a live database or full OTel stack and are appropriately skipped in unit tests.

Version

2.2.22.2.3 (PATCH — tests only)

Checklist

  • ruff check — all passed
  • ruff format --check — all formatted
  • mypy — no issues in 6 source files
  • pytest — 260 passed
  • CHANGELOG.md updated
  • Version bumped in pyproject.toml

@vladiant vladiant merged commit 400b52d into main Apr 4, 2026
4 checks passed
@vladiant vladiant deleted the extend-tests-coverage branch April 4, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant