Skip to content

Fix TreatDiscoveryWarningsAsErrors to throw exception instead of just logging#6202

Closed
Copilot wants to merge 10 commits intorel/4.0from
copilot/fix-5992
Closed

Fix TreatDiscoveryWarningsAsErrors to throw exception instead of just logging#6202
Copilot wants to merge 10 commits intorel/4.0from
copilot/fix-5992

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 28, 2025

The TreatDiscoveryWarningsAsErrors setting was not guaranteeing test run failure when discovery warnings occurred. Previously, it only changed the log level from Warning to Error but didn't actually fail the test run.

Problem

When TreatDiscoveryWarningsAsErrors was enabled in MSTest settings, discovery warnings would be logged as errors but the test discovery would continue normally. This meant that issues like missing test assemblies or other discovery problems might not cause the test run to fail as expected.

Solution

Modified UnitTestDiscoverer.DiscoverTestsInSource() to throw an AdapterSettingsException when TreatDiscoveryWarningsAsErrors is true and warnings are present. This ensures that:

  1. Discovery warnings are still logged as error messages (preserving existing behavior)
  2. An exception is thrown to guarantee test run failure
  3. The exception message contains diagnostic information about the source and warning details

Changes

  • UnitTestDiscoverer.cs: Added exception throwing logic after warning processing
  • UnitTestDiscovererTests.cs: Updated existing test to verify exception behavior and added new test to ensure no regression when setting is disabled

Example

<RunSettings>
  <MSTestV2>
    <TreatDiscoveryWarningsAsErrors>True</TreatDiscoveryWarningsAsErrors>
  </MSTestV2>
</RunSettings>

With these changes, discovery warnings will now cause test runs to fail immediately rather than just being logged as errors.

Fixes #5992.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 37cvsblobprodcus359.vsblob.vsassets.io
    • Triggering command: dotnet build (dns block)
  • 4zjvsblobprodcus390.vsblob.vsassets.io
    • Triggering command: dotnet build (dns block)
  • 7devsblobprodcus323.vsblob.vsassets.io
    • Triggering command: dotnet build (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: dotnet build (dns block)
  • ljcvsblobprodcus317.vsblob.vsassets.io
    • Triggering command: dotnet build (dns block)
  • sqdvsblobprodcus333.vsblob.vsassets.io
    • Triggering command: dotnet build (dns block)
  • st8vsblobprodcus339.vsblob.vsassets.io
    • Triggering command: dotnet build (dns block)
  • ytvvsblobprodcus310.vsblob.vsassets.io
    • Triggering command: dotnet build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] TreatDiscoveryWarningsAsErrors should throw instead of sending message Fix TreatDiscoveryWarningsAsErrors to throw exception instead of just logging Jul 28, 2025
Copilot AI requested a review from Evangelink July 28, 2025 12:34
@Evangelink Evangelink changed the base branch from main to rel/4.0 July 28, 2025 14:05
@Evangelink Evangelink closed this Jul 30, 2025
@Evangelink Evangelink deleted the copilot/fix-5992 branch July 30, 2025 12:44
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.

TreatDiscoveryWarningsAsErrors should throw instead of sending message

3 participants