Skip to content

Commit 8463cf8

Browse files
test(langextract): cover setup behavior with and without optional dependency
Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/cec32ee8-0573-405f-86d1-6a28fb51b609 Co-authored-by: MervinPraison <454862+MervinPraison@users.noreply.github.com>
1 parent 07f9556 commit 8463cf8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/praisonai/tests/unit/test_langextract_sink.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,27 @@ def test_setup_observability_registers_context_emitter(self):
415415
previous_emitter = get_context_emitter()
416416
try:
417417
# Make test deterministic even when optional dependency is not installed.
418-
with patch("importlib.util.find_spec", return_value=object()):
418+
with patch("importlib.util.find_spec", return_value=object()), \
419+
patch("atexit.register"):
419420
cli_app._setup_langextract_observability(verbose=False)
420421
emitter = get_context_emitter()
421422
assert emitter.enabled, "context emitter should be enabled after setup"
422423
finally:
423424
set_context_emitter(previous_emitter)
425+
assert get_context_emitter() is previous_emitter
426+
427+
def test_setup_observability_without_langextract_leaves_context_emitter_unchanged(self):
428+
"""Setup should be a no-op when optional langextract dependency is unavailable."""
429+
import praisonai.cli.app as cli_app
430+
from praisonaiagents.trace.context_events import get_context_emitter, set_context_emitter
431+
432+
previous_emitter = get_context_emitter()
433+
try:
434+
with patch("importlib.util.find_spec", return_value=None):
435+
cli_app._setup_langextract_observability(verbose=False)
436+
assert get_context_emitter() is previous_emitter
437+
finally:
438+
set_context_emitter(previous_emitter)
424439

425440

426441
if __name__ == "__main__":

0 commit comments

Comments
 (0)