Code review shows `except Exception as e: logger.error(e)` everywhere in a new tool. What feedback do you give?
BeginnerScenarioTesting, CI/CD, packaging & services
Answer
Situation read → Errors are swallowed and tracebacks lost.
What I'd do →
- Catch specific exceptions where you can handle them (
ClientErrorwith a specific code,FileNotFoundError). - Use
log.exception(...)to keep the traceback, and add context (which resource, which region). - Re-raise or exit non-zero when you cannot recover.
- Keep one broad catch at the CLI entry point that logs and exits 1.
Why → Swallowed exceptions make tools report success while failing.
Interview tip → "Catch narrow, log with context, fail loudly."
More on Testing, CI/CD, packaging & services
You join a team whose Python automation repo has no tests. Where do you start?BeginnerYour pytest suite takes 12 minutes. How do you speed it up?IntermediateA test passes locally but fails in CI only when run with the rest of the suite. What do you suspect?IntermediateYou want a reusable CI pipeline for 15 Python tool repos. What goes in it?IntermediateYour Python Docker image is 1.1 GB. How do you shrink it?IntermediateYou want to distribute an internal CLI to 200 engineers. What are your options?Intermediate