-
Notifications
You must be signed in to change notification settings - Fork 288
Add MSTEST0058: Detect conflicting Parallelize and DoNotParallelize attributes with code fixes #6823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ze attributes Co-authored-by: Evangelink <[email protected]>
There was a problem hiding this 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.
Co-authored-by: Evangelink <[email protected]>
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:
If you need me to access, download, or install something from one of these locations, you can either:
|
src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Evangelink <[email protected]>
…pdate description Co-authored-by: Evangelink <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Add a new test where you would have multiple asm attributes like:
[assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel), MyAsm]
[assembly: DoNotParallelize, MyAsm]
where MyAsm is a locally generated asm level attribute
Co-authored-by: Evangelink <[email protected]>
Added in 62102dd. The new test |
|
@copilot Let's remove the codefixer (and adjust the tests) |
Co-authored-by: Evangelink <[email protected]>
Removed in 7680a70. Deleted the code fixer file and reverted all related CodeFixResources changes. Updated tests to use EmptyCodeFixProvider and removed all code fix test methods. Kept the diagnostic tests including the one for multiple attributes in the same attribute list. |
|
@copilot fix @azure-pipelines test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs(34,1): error : Test method MSTest.Analyzers.Test.UseParallelizeAttributeAnalyzerTests.WhenBothAttributesSet_Diagnostic threw exception: Expected diagnostic: Actual diagnostic: @azure-pipelines test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs(34,1): error : Test method MSTest.Analyzers.Test.UseParallelizeAttributeAnalyzerTests.WhenBothAttributesSetWithMultipleAttributesInList_Diagnostic threw exception: Diagnostics: @azure-pipelines test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs(34,1): error : Test method MSTest.Analyzers.Test.UseParallelizeAttributeAnalyzerTests.WhenBothAttributesSetInDifferentOrder_Diagnostic threw exception: Expected diagnostic: Actual diagnostic: |
Co-authored-by: Evangelink <[email protected]>
Fixed in 2d1f9c6. The test location markers now correctly point to the attribute names (not the entire |
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:
Test Coverage:
[assembly: Parallelize(...), MyAsm])Localization:
{Locked="..."}) to resource strings to prevent translation of attribute names[Parallelize]and[DoNotParallelize]Documentation:
[DoNotParallelize]takes precedence and parallelization will be disabledBug Fix:
Improvements:
<issue_title>MSTEST0001: Explicitly enable or disable tests parallelization</issue_title>
Original prompt
💡 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.