-
Notifications
You must be signed in to change notification settings - Fork 275
Add CIConditionAttribute to support CI-specific test execution control #5797
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
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
CIConditionAttribute
public override bool ShouldRun | ||
{ | ||
get | ||
{ | ||
bool isCI = IsCIEnvironment(); | ||
return Mode == ConditionMode.Include ? isCI : !isCI; | ||
} | ||
} |
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.
public override bool ShouldRun | |
{ | |
get | |
{ | |
bool isCI = IsCIEnvironment(); | |
return Mode == ConditionMode.Include ? isCI : !isCI; | |
} | |
} | |
public override bool ShouldRun => IsCIEnvironment(); |
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.
Done! Changed to public override bool ShouldRun => IsCIEnvironment();
to follow the same pattern as OSConditionAttribute
. The framework handles the Mode logic in AttributeHelpers.cs
. Commit: 7764d1e
…ework pattern Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI 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:
|
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Linq; |
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.
Remove
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.
Done! Removed the using System.Linq;
statement and replaced the LINQ All()
method with a traditional foreach loop to eliminate the dependency. Commit: d3fc478
|
||
return false; | ||
} | ||
} |
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.
src/TestFramework/TestFramework/Attributes/TestMethod/CIConditionAttribute.cs(119,2): error SA1518: (NETCORE_ENGINEERING_TELEMETRY=Build) File is required to end with a single newline character (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1518.md)
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.
Fixed! Added the missing newline character at the end of the file to resolve the StyleCop SA1518 error. Commit: 29c801e
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
…te.cs Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI 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:
|
This PR implements
CIConditionAttribute
to allow developers to conditionally run or skip tests based on whether they are executing in a Continuous Integration (CI) environment.Summary
The new attribute addresses a common need in test suites where certain tests should behave differently in CI environments - either running only in CI or being temporarily disabled in CI (e.g., for flaky tests).
Usage
Implementation Details
Follows existing patterns: Inherits from
ConditionBaseAttribute
likeOSConditionAttribute
Comprehensive CI detection: Supports major CI systems including:
GITHUB_ACTIONS
)TF_BUILD
)APPVEYOR
)TRAVIS
)CIRCLECI
)BUILD_ID
+BUILD_URL
)TEAMCITY_VERSION
)CODEBUILD_BUILD_ID
+AWS_REGION
)BUILD_ID
+PROJECT_ID
)JB_SPACE_API_URL
)CI
)CI detection logic: Based on the well-documented detection from .NET SDK telemetry (https://learn.microsoft.com/dotnet/core/tools/telemetry#continuous-integration-detection)
Comprehensive testing: 20+ unit tests covering all CI detection scenarios and edge cases
API consistency: Updated PublicAPI files for proper API tracking
Use Cases
The attribute can be applied to both test methods and test classes, supporting standard MSTest condition attribute grouping behavior.
Fixes #5533.
💡 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.