FastAPI + GitHub Actions: Fixing Silent Dependency Issues

2 days of debugging. Fixed by adding 1 line. 😅 If you use FastAPI + GitHub Actions, read this. I was building a Tier 2 Event Pipeline with FastAPI microservices. Everything worked perfectly on my machine — 8/8 tests passing, 96% coverage, Docker builds clean. Pushed to GitHub Actions. Two jobs failed instantly. ❌ Python Checks (ingestion-service) — FAILED ❌ Python Checks (fusion-engine-service) — FAILED The error: RuntimeError: The starlette.testclient module requires the httpx package. Both services used TestClient from FastAPI in their tests. TestClient has a hard runtime dependency on httpx. But httpx was nowhere in my pyproject.toml. So why did it work locally? My Windows machine already had httpx installed — silently pulled in as a transitive dependency from earlier work. I never noticed because it was never declared. GitHub Actions runners are clean Ubuntu containers. They install only what you declare. Nothing more. Classic "works on my machine" — and I had no idea. ───────────────────── The fix? One line in each pyproject.toml: [project.optional-dependencies] dev = [   "pytest>=8.3,<10.0",   "pytest-cov>=5.0,<6.0", +  "httpx>=0.27,<1.0",  ← this ] ───────────────────── All jobs green. ✅ The real lessons I'm keeping with me: ① If your test imports it → it's a dev dependency. No exceptions. ② Coverage at 2% and 39% wasn't the bug. It was a symptom. The tests couldn't even be collected. Always read the FIRST error, not the summary. ③ Before every push, test in a clean venv: python -m venv .venv-clean source .venv-clean/bin/activate pip install -e ".[dev]" pytest tests This single habit would have saved me 2 days. If you're using FastAPI + TestClient + GitHub Actions — double-check your pyproject.toml right now. You might have the same silent bomb waiting. Ever lost hours to a "works on my machine" bug? Drop it in the comments 👇 #Python #FastAPI #GitHubActions #CI #DevOps #SoftwareEngineering #LessonsLearned #OpenSource #Testing

To view or add a comment, sign in

Explore content categories