본문 바로가기
C.W.K.
Stream
Lesson 02 of 07 · published

DeepEval: pytest 기반 Python 프레임워크

~22 min · frameworks, deepeval, pytest, python

Level 0추측자
0 XP0/55 lessons0/10 achievements
0/150 XP to next level150 XP to go0% complete

Python 테스트처럼 작성하는 평가

DeepEval(2026년 중반 기준 v3.x)은 Python 기반 평가 프레임워크야. pytest와 통합되며 RAG·에이전트·안전성 지표와 사용자 정의 지표를 포함해 30종 이상의 지표를 제공하고, Confident AI의 클라우드 대시보드도 선택적으로 사용할 수 있어. 평가 로직을 Python으로 작성하고 이미 pytest를 쓰고 있다면 특히 잘 맞아.

기본으로 제공하는 기능

  • pytest 통합assert_test를 사용해 평가를 일반 pytest 테스트처럼 작성해.
  • 내장 지표 — 충실성, AnswerRelevancy, 환각, Toxicity, 편향, 문맥 정밀도·문맥 재현율·문맥 관련성, ToolCallAccuracy, AgentGoalAccuracy, GEval 같은 지표를 제공해.
  • 종단 간 평가와 추적 모드 — 최종 출력만 보는 블랙박스 평가와 파이프라인의 실행 과정을 살펴보는 화이트박스 평가를 모두 지원해.
  • deepeval login으로 로그인하면 실험 기록을 공유할 수 있는 클라우드 대시보드를 사용할 수 있어.
  • 평가 데이터를 생성하는 합성기를 제공해.

특히 잘 맞는 경우

DeepEval은 Python 코드베이스에 자연스럽게 어울려. 평가 모음을 tests/eval/ 디렉터리에 두면 pytest가 수집하고 CI가 실행할 수 있어. GEval을 사용하면 평가 프롬프트를 일일이 직접 작성하지 않고도 선언형 기준으로 사용자 정의 LLM 판정 로직을 만들 수 있어.

잘 맞지 않는 경우

팀에서 Python을 사용하지 않는다면 도입 과정에서 상당한 마찰이 생겨. 코드를 작성하지 않고 사용할 수 있는 시각적 화면이 필요하다면 Braintrust나 Confident AI의 호스팅형 화면을 살펴봐.

원칙: 평가 코드를 Python 애플리케이션 옆에 두고 다른 테스트와 똑같이 다루고 싶다면 DeepEval이 올바른 선택이야.

Code

설치와 로그인·bash
pip install -U deepeval

# Optional: login to Confident AI for cloud dashboard
deepeval login

# Run a single test file
deepeval test run test_eval.py

# Or via pytest
pytest test_eval.py -v
test_eval.py — GEval 사용자 정의 지표·python
from deepeval import assert_test
from deepeval.test_case import LLMTestCase, LLMTestCaseParams
from deepeval.metrics import GEval

def test_correctness():
    correctness = GEval(
        name="Correctness",
        criteria="Determine whether the actual output is factually correct given the expected output.",
        evaluation_params=[
            LLMTestCaseParams.ACTUAL_OUTPUT,
            LLMTestCaseParams.EXPECTED_OUTPUT,
        ],
        threshold=0.5,
    )
    case = LLMTestCase(
        input="What is the capital of France?",
        actual_output="Paris is the capital of France.",
        expected_output="Paris",
    )
    assert_test(case, [correctness])
RAG 전용 내장 지표·python
from deepeval.metrics import (
    AnswerRelevancyMetric,
    FaithfulnessMetric,
    ContextualPrecisionMetric,
    ContextualRecallMetric,
    HallucinationMetric,
)

faithfulness = FaithfulnessMetric(threshold=0.7)
relevancy = AnswerRelevancyMetric(threshold=0.7)

case = LLMTestCase(
    input="What is the latest iPhone?",
    actual_output="The iPhone 17 Pro has a 48MP main camera.",
    retrieval_context=["iPhone 17 Pro features a 48MP main camera, A19 chip, ..."],
)
assert_test(case, [faithfulness, relevancy])

External links

Exercise

RAG 충실성을 측정하고 싶은 기능을 골라. DeepEval을 설치하고 검색 맥락이 포함된 평가 사례 5개를 작성한 뒤 FaithfulnessMetric과 AnswerRelevancyMetric으로 검증해. 마지막으로 pytest 기반 CI에 연결해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.