Merge pull request #21434 from BerriAI/fix/langfuse-otel-sys-modules-leak

fix: restore sys.modules after stub injection in langfuse otel test
This commit is contained in:
jquinter
2026-02-17 22:32:12 -03:00
committed by GitHub
@@ -157,8 +157,12 @@ class TestLangfuseOtelIntegration:
stub_module.LangFuseLogger = StubLFLogger # type: ignore
# Register stub in sys.modules so import inside method succeeds
sys.modules["litellm.integrations.langfuse.langfuse"] = stub_module # type: ignore
# Register stub in sys.modules so import inside method succeeds.
# Use monkeypatch so the real module is restored after the test runs,
# preventing sys.modules corruption that would break patch() targets in
# later tests (the patch would hit the stub while the real module's
# globals remain unpatch-ed).
monkeypatch.setitem(sys.modules, "litellm.integrations.langfuse.langfuse", stub_module) # type: ignore
kwargs = {"litellm_params": {"metadata": {"foo": "bar"}}}
extracted = LangfuseOtelLogger._extract_langfuse_metadata(kwargs)