Skip to content

test(feedback): mock Cohere client in test fixtures and allow optional client injection - #21

Open
ravimahatonp wants to merge 1 commit into
ChainLearnOfficial:mainfrom
ravimahatonp:mock-cohere-client-test-fixture
Open

ravimahatonp wants to merge 1 commit into
ChainLearnOfficial:mainfrom
ravimahatonp:mock-cohere-client-test-fixture

Conversation

@ravimahatonp

Copy link
Copy Markdown

Summary

This PR enables tests to execute without requiring a real COHERE_API_KEY environment variable. Previously, running tests in an environment without COHERE_API_KEY resulted in a pydantic ValidationError upon importing settings. Furthermore, FeedbackEngine instantiated a live CohereClient unconditionally in __init__.

Changes Made

  • src/config.py: Provided a safe default empty string for cohere_api_key so that importing configuration and services does not fail validation during unit testing.
  • src/services/feedback_engine.py: Supported client dependency injection via __init__(self, client: Any = None) so that mock clients can be passed cleanly.
  • tests/test_feedback_engine.py: Injected MagicMock() client into the FeedbackEngine fixtures for TestFeedbackScoreComputation and TestQuickFeedback, decoupling unit tests from external Cohere client instantiation.

Closes #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test fixture requires COHERE_API_KEY for non-API tests

1 participant