Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ninghu committed Apr 18, 2024
1 parent d1d8937 commit e1b0785
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/promptflow-evals/tests/evals/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import patch

import pytest
from azure.identity import DefaultAzureCredential
from pytest_mock import MockerFixture

from promptflow.client import PFClient
Expand All @@ -13,6 +14,7 @@
from promptflow.tracing._integrations._openai_injector import inject_openai_api

try:
from promptflow.recording.azure import FakeTokenCredential
from promptflow.recording.local import recording_array_reset
from promptflow.recording.record_mode import is_in_ci_pipeline, is_live, is_record, is_replay
except ImportError:
Expand Down Expand Up @@ -91,6 +93,15 @@ def project_scope() -> dict:
return dev_connections[conn_name]["value"]


@pytest.fixture
def azure_credential():
# CI pipeline currently does not support DefaultAzureCredential
if pytest.is_replay:
return FakeTokenCredential()

return DefaultAzureCredential()


@pytest.fixture
def pf_client() -> PFClient:
"""The fixture, returning PRClient"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from promptflow.evals.evaluators.qa import QAEvaluator


@pytest.mark.usefixtures("model_config", "project_scope", "recording_injection")
@pytest.mark.usefixtures("model_config", "project_scope", "azure_credential", "recording_injection")
@pytest.mark.e2etest
class TestBuiltInEvaluators:
def test_individual_evaluator_prompt_based(self, model_config):
Expand All @@ -17,8 +17,8 @@ def test_individual_evaluator_prompt_based(self, model_config):
assert score is not None
assert score["gpt_fluency"] > 1.0

def test_individual_evaluator_service_based(self, project_scope):
eval_fn = ViolenceEvaluator(project_scope)
def test_individual_evaluator_service_based(self, project_scope, azure_credential):
eval_fn = ViolenceEvaluator(project_scope, azure_credential)
score = eval_fn(
question="What is the capital of Japan?",
answer="The capital of Japan is Tokyo.",
Expand Down Expand Up @@ -59,8 +59,8 @@ def test_composite_evaluator_qa(self, model_config, parallel):
(True),
],
)
def test_composite_evaluator_content_safety(self, project_scope, parallel):
safety_eval = ContentSafetyEvaluator(project_scope, parallel=parallel)
def test_composite_evaluator_content_safety(self, project_scope, parallel, azure_credential):
safety_eval = ContentSafetyEvaluator(project_scope, parallel, azure_credential)
score = safety_eval(
question="Tokyo is the capital of which country?",
answer="Japan",
Expand Down

0 comments on commit e1b0785

Please sign in to comment.