Skip to content

Commit 0cf8d97

Browse files
authored
fix(feedback): fix patching flakes with test_openai.py (#95577)
Discovered in #95392 the monkeypatching of `OpenAI` class in `test_create_feedback.py` can affect `test_openai.py`, I'm guessing when they are ran in parallel. I haven't seen this flake anywhere else, but don't believe it's related to the changes in #95392. Using the patch context manager should fix this. "not spam" return value bleeds over to the openai test: <img width="806" height="476" alt="Screenshot 2025-07-15 at 10 51 22 AM" src="https://github.com/user-attachments/assets/d900d7d1-9138-422f-b354-ac94fad9967a" /> Ref [REPLAY-513: [PR Tracker] refactor backend user feedback code](https://linear.app/getsentry/issue/REPLAY-513/pr-tracker-refactor-backend-user-feedback-code)
1 parent 239850c commit 0cf8d97

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

tests/sentry/feedback/test_create_feedback.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ def test_create_feedback_spam_detection_produce_to_kafka(
451451
mock_produce_occurrence_to_kafka,
452452
input_message,
453453
expected_result,
454-
monkeypatch,
455454
feature_flag,
456455
):
457456
with Feature({"organizations:user-feedback-spam-ingest": feature_flag}):
@@ -491,11 +490,10 @@ def test_create_feedback_spam_detection_produce_to_kafka(
491490
mock_openai = Mock()
492491
mock_openai().chat.completions.create = create_dummy_openai_response
493492

494-
monkeypatch.setattr("sentry.llm.providers.openai.OpenAI", mock_openai)
495-
496-
create_feedback_issue(
497-
event, default_project.id, FeedbackCreationSource.NEW_FEEDBACK_ENVELOPE
498-
)
493+
with patch("sentry.llm.providers.openai.OpenAI", mock_openai):
494+
create_feedback_issue(
495+
event, default_project.id, FeedbackCreationSource.NEW_FEEDBACK_ENVELOPE
496+
)
499497

500498
# Check if the 'is_spam' evidence in the Kafka message matches the expected result
501499
is_spam_evidence = [
@@ -526,7 +524,6 @@ def test_create_feedback_spam_detection_produce_to_kafka(
526524
def test_create_feedback_spam_detection_project_option_false(
527525
default_project,
528526
mock_produce_occurrence_to_kafka,
529-
monkeypatch,
530527
):
531528
default_project.update_option("sentry:feedback_ai_spam_detection", False)
532529

@@ -567,11 +564,10 @@ def test_create_feedback_spam_detection_project_option_false(
567564
mock_openai = Mock()
568565
mock_openai().chat.completions.create = create_dummy_openai_response
569566

570-
monkeypatch.setattr("sentry.llm.providers.openai.OpenAI", mock_openai)
571-
572-
create_feedback_issue(
573-
event, default_project.id, FeedbackCreationSource.NEW_FEEDBACK_ENVELOPE
574-
)
567+
with patch("sentry.llm.providers.openai.OpenAI", mock_openai):
568+
create_feedback_issue(
569+
event, default_project.id, FeedbackCreationSource.NEW_FEEDBACK_ENVELOPE
570+
)
575571

576572
# Check if the 'is_spam' evidence in the Kafka message matches the expected result
577573
is_spam_evidence = [
@@ -588,7 +584,6 @@ def test_create_feedback_spam_detection_project_option_false(
588584
@django_db_all
589585
def test_create_feedback_spam_detection_set_status_ignored(
590586
default_project,
591-
monkeypatch,
592587
):
593588
with Feature(
594589
{
@@ -632,11 +627,10 @@ def test_create_feedback_spam_detection_set_status_ignored(
632627
mock_openai = Mock()
633628
mock_openai().chat.completions.create = create_dummy_openai_response
634629

635-
monkeypatch.setattr("sentry.llm.providers.openai.OpenAI", mock_openai)
636-
637-
create_feedback_issue(
638-
event, default_project.id, FeedbackCreationSource.NEW_FEEDBACK_ENVELOPE
639-
)
630+
with patch("sentry.llm.providers.openai.OpenAI", mock_openai):
631+
create_feedback_issue(
632+
event, default_project.id, FeedbackCreationSource.NEW_FEEDBACK_ENVELOPE
633+
)
640634

641635
group = Group.objects.get()
642636
assert group.status == GroupStatus.IGNORED

0 commit comments

Comments
 (0)