TAG
Testing
Everything filed under this tag.
3 entries01Writing
Generator Exceptions Surface on the First next(): try Around create_chat_completion(stream=True) Never Sees the Context Window Error2026-11-08Calling a generator function only builds a generator; the body, including any raise in it, runs on the first next(). llama-cpp-python checks the context window inside such a body, so the try around a streaming call, and the shrink-and-retry under it, never fire with the real library. The test double raised at call time, so the tests passed with 100% coverage.#Python#LLM#Error Handling#Testing#AutarkiaMagicMock accepts any arguments: the caller passes one too many, the test passes, production raises TypeError and except swallows it2026-10-17A MagicMock without a spec doesn’t check call signatures; when the code under test passes the wrong arguments, the double still returns whatever you configured. In Autarkia this meant a block of prompt context was never injected: the real method took only self, the caller passed a user_id, the test double accepted it, and in production the TypeError was swallowed by an outer except.#Python#Testing