Skip to content

Add CulturedConditionalFactAttribute and CulturedConditionalTheoryAttribute to XUnitV3Extensions#16825

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/add-cultured-conditional-attributes
Open

Add CulturedConditionalFactAttribute and CulturedConditionalTheoryAttribute to XUnitV3Extensions#16825
Copilot wants to merge 4 commits into
mainfrom
copilot/add-cultured-conditional-attributes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 17, 2026

Adds conditional variants of CulturedFactAttribute and CulturedTheoryAttribute that support CalleeType and ConditionMemberNames, matching the pattern of the existing ConditionalFact/ConditionalTheory attributes.

These derive from CulturedFactAttribute/CulturedTheoryAttribute (xunit v3 only) and use the existing ConditionalTestDiscoverer.EvaluateSkipConditions to set Skip at construction time. Constructors include [CallerFilePath] and [CallerLineNumber] source information parameters to avoid xUnit3003 errors.

  • New attributes in Microsoft.DotNet.XUnitV3Extensions/src/:
    • CulturedConditionalFactAttribute — extends CulturedFactAttribute
    • CulturedConditionalTheoryAttribute — extends CulturedTheoryAttribute
  • Tests in CulturedConditionalAttributeTests.cs: skip state validation, property exposure (CalleeType, ConditionMemberNames, Cultures), theory data passthrough, culture verification via CultureInfo.CurrentCulture
[CulturedConditionalFact(new[] { "en-US", "fr-FR" }, typeof(MyTests), new[] { nameof(IsSupported) })]
public void RunsPerCultureWhenConditionMet() { }

[CulturedConditionalTheory(new[] { "en-US", "ja-JP" }, typeof(MyTests), new[] { nameof(IsSupported) })]
[InlineData(42)]
public void TheoryRunsPerCultureWhenConditionMet(int value) { }

To double check:

Copilot AI and others added 2 commits May 16, 2026 18:45
Agent-Logs-Url: https://github.com/dotnet/arcade/sessions/d4c6180b-97a0-40ce-b44f-563c59ba63bd

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

Adds xUnit v3 cultured conditional test attributes so tests can combine culture-specific execution with existing conditional skip evaluation.

Changes:

  • Adds CulturedConditionalFactAttribute.
  • Adds CulturedConditionalTheoryAttribute.
  • Adds tests validating skip behavior, exposed properties, theory data passthrough, and culture selection.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Microsoft.DotNet.XUnitV3Extensions/src/CulturedConditionalFactAttribute.cs Adds the cultured conditional fact attribute implementation.
src/Microsoft.DotNet.XUnitV3Extensions/src/CulturedConditionalTheoryAttribute.cs Adds the cultured conditional theory attribute implementation.
src/Microsoft.DotNet.XUnitV3Extensions/tests/CulturedConditionalAttributeTests.cs Adds xUnit v3 tests covering the new attributes.

Comment thread src/Microsoft.DotNet.XUnitV3Extensions/tests/CulturedConditionalAttributeTests.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AndriySvyryd AndriySvyryd marked this pull request as ready for review May 17, 2026 21:58
public class CulturedConditionalAttributeTests
{
// These tests validate the xunit v3 cultured conditional attributes without relying on
// execution order, which the v3 runner does not guarantee for this scenario.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@AndriySvyryd won't this potentially cause issues if the tests run concurrently with other tests and the process culture is changed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That would be an issue in XUnit.
https://github.com/xunit/xunit/blob/main/src/xunit.v3.core/ObjectModel/CulturedXunitTestCase.cs#L103 sets it globally, but in V2 it was set only for a specific thread:
https://github.com/xunit/xunit/blob/main/src/xunit.v2.tests/TestUtility/CultureAwareTesting/CulturedXunitTestCase.cs#L53
This looks like a deliberate change, so there must be some mechanism to isolate the other tests.
@bradwilson Would you like to weigh it?

Copy link
Copy Markdown

@bradwilson bradwilson May 19, 2026

Choose a reason for hiding this comment

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

Yeah, these should be using Thread.CurrentCulture and Thread.CurrentUICulture instead of CultureInfo. I'm not sure why that changed... 🤔

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actually, using CultureInfo.CurrentCulture is correct according to the docs: https://learn.microsoft.com/dotnet/api/system.globalization.cultureinfo.currentculture

Gets or sets the CultureInfo object that represents the culture used by the current thread and task-based asynchronous operations.

@bradwilson
Copy link
Copy Markdown

I'm not sure what the purpose of these classes are, since [CulturedFact] and [CulturedTheory] in v3 already support conditional skipping via SkipUnless or SkipWhen.

@bradwilson
Copy link
Copy Markdown

Also, you're missing source information constructor parameters, which should be causing xUnit3003 to trigger.

@AndriySvyryd
Copy link
Copy Markdown
Member

AndriySvyryd commented May 19, 2026

I'm not sure what the purpose of these classes are, since [CulturedFact] and [CulturedTheory] in v3 already support conditional skipping via SkipUnless or SkipWhen.

SkipUnless and SkipWhen only support public static properties on the test class. This attribute (and the others like https://github.com/dotnet/arcade/blob/main/src/Microsoft.DotNet.XUnitExtensions.Shared/Attributes/ConditionalFactAttribute.cs) allows to reference any static member on any type. It also allows to specify multiple conditions.

@bradwilson
Copy link
Copy Markdown

SkipType allows reference to other types, but it is true that we only support properties. If you need to support methods, that would make sense.

Comment thread src/Microsoft.DotNet.XUnitV3Extensions/src/CulturedConditionalFactAttribute.cs Outdated
Copilot AI requested review from Copilot and removed request for Copilot May 19, 2026 22:39
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 19, 2026

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 addresses (expand for details)

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

  • xunit.net
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (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 AndriySvyryd May 19, 2026 22:40
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.

5 participants