Skip to content

FIX: flaky target capabilities tests causing intermittent failures#1527

Merged
rlundeen2 merged 3 commits intomicrosoft:mainfrom
rlundeen2:users/rlundeen/2026_03_21_flaky_test
Mar 24, 2026
Merged

FIX: flaky target capabilities tests causing intermittent failures#1527
rlundeen2 merged 3 commits intomicrosoft:mainfrom
rlundeen2:users/rlundeen/2026_03_21_flaky_test

Conversation

@rlundeen2
Copy link
Copy Markdown
Contributor

@rlundeen2 rlundeen2 commented Mar 21, 2026

The env vars would get polluted when running in parallel, causing test failures

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR stabilizes unit tests around PromptTarget capability resolution by preventing leaked OPENAI_*_UNDERLYING_MODEL environment variables (potentially set by .env loading in other tests) from changing targets from _DEFAULT_CAPABILITIES to _KNOWN_CAPABILITIES.

Changes:

  • Added per-test/per-fixture patch.dict("os.environ", ...) guards to neutralize *_UNDERLYING_MODEL env vars during capability assertions.
  • Centralized the “clean env” mapping within each affected test module for readability and reuse within that module.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/unit/target/test_target_capabilities.py Ensures OpenAIVideoTarget modality assertions aren’t affected by leaked underlying-model env vars.
tests/unit/target/test_supports_multi_turn.py Ensures OpenAIVideoTarget supports_multi_turn assertion isn’t flipped by leaked underlying-model env vars.
tests/unit/target/test_realtime_target.py Applies env cleanup at the RealtimeTarget fixture level to keep realtime tests deterministic.

@rlundeen2 rlundeen2 changed the title FIX: faky target capabilities tests causing intermittent failures FIX: flaky target capabilities tests causing intermittent failures Mar 21, 2026
rlundeen2 and others added 2 commits March 21, 2026 11:32
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add OPENAI_COMPLETION_UNDERLYING_MODEL and OPENAI_RESPONSES_UNDERLYING_MODEL
  to _CLEAN_UNDERLYING_MODEL_ENV in test_target_capabilities.py
- Apply @patch.dict to all OpenAI target test methods in
  TestTargetCapabilitiesModalities (chat, image, tts, realtime, response,
  completion) - not just video
- Add @patch.dict to TTS and completion tests in test_supports_multi_turn.py
- Add TTS and completion env vars to test_supports_multi_turn.py dict

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 merged commit 2e8ef05 into microsoft:main Mar 24, 2026
38 checks passed
jbolor21 pushed a commit to jbolor21/jbolor-PyRIT that referenced this pull request Mar 25, 2026
…icrosoft#1527)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants