fix: prevent duplicate test-case rows on pytest retry#2619
Open
amitkojha05 wants to merge 3 commits intoconfident-ai:mainfrom
Open
fix: prevent duplicate test-case rows on pytest retry#2619amitkojha05 wants to merge 3 commits intoconfident-ai:mainfrom
amitkojha05 wants to merge 3 commits intoconfident-ai:mainfrom
Conversation
|
@amitkojha05 is attempting to deploy a commit to the Confident AI Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
@penguine-ip Please review this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a test is marked with
pytest.mark.flakyorpytest-rerunfailures,assert_test()is called again from scratch on every retry attempt.Each call flows through:assert_test() → execute_test_cases() → update_test_run() → add_test_case()
add_test_case()blindly appended on every call with no duplicate check.A test that passed on the 3rd attempt would appear on the Confident AI dashboard as 2 failures + 1 pass instead of just 1 pass.
The same unconditional append also double-counted
evaluation_cost— a test costing0.01on attempt 1 and0.02on attempt 2 accumulated0.03on the run total instead of the correct0.02.Root cause
TestRun.add_test_case()indeepeval/test_run/test_run.py— no deduplication by test-case name before appending toself.test_casesorself.conversational_test_cases.Fix
One method changed, one file touched:
deepeval/test_run/test_run.py.add_test_case()now scans the target list for an existing entry with the samename. On a match it replaces that slot (latest attempt wins) and backs the replaced attempt'sevaluation_costout of the run total before applying the new one. New test cases still append as before via Python'sfor/else.Before / after
Tests
Added
tests/test_core/test_run/test_test_run_retry_overwrite.py— 10 tests, all passing on Python 3.10 and 3.12:successwinsNonecost backs out previous cost correctlyNonecost, retry sets cost correctlyCaveat
Deduplication keys on
name. If two genuinely distinct test cases share the same display name in one run, the second would silently overwrite the first. Pytest node IDs are unique by default so this shouldn't occur in practice — flagging it in case maintainers prefer a stricter key (e.g.nodeid) in future.Checklist
pytest.mark.flaky#1992deepeval/test_run/test_run.py+ new test file