Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

Add analyzer MSTEST0058 to prevent having both Parallelize and DoNotParallelize assembly attributes

Summary

This PR implements a new analyzer (MSTEST0058) that detects and reports a warning when an assembly has both [Parallelize] and [DoNotParallelize] attributes, which creates an ambiguous configuration.

Implementation Details

Analyzer Logic:

  • MSTEST0058 checks for conflicting attributes first and reports regardless of test adapter presence
  • Diagnostics are reported with locations pointing to both attribute declarations (on the attribute name itself)
  • MSTEST0001 (missing attributes) only checks when test adapter is referenced

Test Coverage:

  • Tests for both attributes present in same order
  • Tests for both attributes present in different orders
  • Tests cover scenarios with and without MSTest adapter referenced
  • Tests expect diagnostics on both attribute locations (on the attribute names)
  • Test for multiple attributes in same attribute list (e.g., [assembly: Parallelize(...), MyAsm])

Localization:

  • Added Locked markers ({Locked="..."}) to resource strings to prevent translation of attribute names [Parallelize] and [DoNotParallelize]
  • Fixed Locked format to use multiple {Locked=...} instead of comma-separated values

Documentation:

  • Updated analyzer description to clarify that when both attributes are present, [DoNotParallelize] takes precedence and parallelization will be disabled

Bug Fix:

  • Fixed logic so MSTEST0058 reports even when test adapter is not referenced
  • Moved test adapter check to only apply to MSTEST0001 diagnostic

Improvements:

Original prompt

This section details on the original issue you should resolve

<issue_title>MSTEST0001: Explicitly enable or disable tests parallelization</issue_title>
<issue_description>I don't know what to say but this warning is just stupid.

And the implementation allows to define [assembly: Microsoft.VisualStudio.TestTools.UnitTesting.DoNotParallelize] in one cs file and in another [assembly: Microsoft.VisualStudio.TestTools.UnitTesting.Parallelize]. So what setting is now chosen?</issue_description>

<agent_instructions>Create a new analyzer that will prevent having both assembly level attributes DoNotParallelize and Parallelize</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@Evangelink > I don't know what to say but this warning is just stupid.

@Balkoth thanks for the constructive feedback ;)

Jokes aside the rule is in place because we have seen many repositories that would benefit from having parallelism enabled but some cannot be enabled for reasons. Instead of simply staying in the limbo state, having explicit call and ideally comment about why it's not parallelisable is good.

And the implementation allows to define [assembly: Microsoft.VisualStudio.TestTools.UnitTesting.DoNotParallelize] in one cs file and in another [assembly: Microsoft.VisualStudio.TestTools.UnitTesting.Parallelize]. So what setting is now chosen?

Thank you! I hadn't realize this. I think short-term we should introduce an analyzer to guard against this case and mid-term we should probably consider merging attributes into a single one.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add analyzer to prevent conflicting test parallelization attributes Add MSTEST0058: Detect conflicting Parallelize and DoNotParallelize attributes Oct 29, 2025
Copilot AI requested a review from Evangelink October 29, 2025 14:15
Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

@copilot some tests are broken

test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs#L34

test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs(34,1): error : Test method MSTest.Analyzers.Test.UseParallelizeAttributeAnalyzerTests.WhenBothAttributesSetInDifferentOrder_Diagnostic threw exception:
System.InvalidOperationException: Context: Diagnostics of test state
Mismatch between number of diagnostics returned, expected "1" actual "0"

Diagnostics:
NONE.

Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot some tests are broken

test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs#L34...

Fixed in c458eb3. The issue was that the test adapter check was happening before the conflicting attributes check, preventing MSTEST0058 from being reported when the adapter wasn't referenced. I've reordered the logic so MSTEST0058 is now reported regardless of test adapter presence, while MSTEST0001 (missing attributes) still only reports when the adapter is referenced.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

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

  • u6ovsblobprodcus377.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/11.0.0-beta.25528.1.txt (dns block)

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

Copilot AI requested a review from Evangelink October 29, 2025 15:09
@Evangelink Evangelink marked this pull request as ready for review October 29, 2025 16:11
@Evangelink Evangelink enabled auto-merge (squash) October 29, 2025 16:11
@Youssef1313 Youssef1313 changed the title Add MSTEST0058: Detect conflicting Parallelize and DoNotParallelize attributes Add MSTEST0059: Detect conflicting Parallelize and DoNotParallelize attributes Dec 4, 2025
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.

MSTEST0001: Explicitly enable or disable tests parallelization

3 participants