Skip to content

Fix culture-dependent test failures by setting en-US culture - #7580

Merged
zivkan merged 3 commits into
NuGet:devfrom
gekka:SetThreadCultureForTestProjects
Aug 25, 2026
Merged

zivkan merged 3 commits into
NuGet:devfrom
gekka:SetThreadCultureForTestProjects

Conversation

@gekka

@gekka gekka commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Bug

Fixes: Nuget/Home#15004

Description

This PR ensures that tests run under the en-US culture by default.

Many existing tests contain assertions that compare localized messages against English-language expected values. Running the test suite under a non-English culture can therefore cause unrelated test failures.

By setting the test culture to en-US, test results become consistent across different environments and system locales.

Note

This PR removes the SkipShared setting from NuGet.VisualStudio.Implementation.Test.csproj.

I could not determine why SkipShared was configured for this project. Other test projects in the solution do not use this setting, and removing it is necessary for the proposed culture configuration to be applied consistently.

However, since I do not know the original reason for this project-specific setting, this change may be unintended.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

Update

I understand that UseCultureAttribute can be applied to individual tests to address culture-related failures. However, the scale of the problem is much larger. On my machine, simply running: .\build.ps1 -RunUnitTests results in more than 440 test failures under a non-English culture.

Since -RunUnitTests executes only the unit tests, I would expect the number of failures to be even higher when running the full test suite via: PowerShell1.\runTests.ps1

I cannot provide an exact number that running on CI because much of the full test suite is intended to run on dedicated CI machines and is not readily executable by external contributors.

While it is theoretically possible to fix these failures by adding UseCultureAttribute to each affected test, doing so would require a significant amount of work and would be difficult to maintain over time.
More importantly, the current situation demonstrates that relying on individual developers to remember to apply UseCultureAttribute is not a reliable solution. There are already many tests that contain culture-dependent assertions without the attribute, and it is likely that future tests will continue to be added without it.
The goal of this PR is to address the issue at the test framework level by providing a consistent culture for all test executions. This allows existing tests to pass without requiring hundreds of individual modifications and helps prevent similar issues from being introduced in the future.

Update 2

I found another issue with the suggestion of simply applying UseCultureAttribute to the affected tests.

For example:

public void ListCommand_WithoutNugetShowStack_HidesStack()
{
// Arrange
var nugetexe = Util.GetNuGetExePath();
var hostName = Guid.NewGuid().ToString();
var expected = $"The remote name could not be resolved: '{hostName}'";
if (RuntimeEnvironmentHelper.IsMono)
{
expected = "No such host is known";
}
var args = new[] { "list", "-Source", "https://" + hostName + "/" };
// Act
var result = CommandRunner.Run(
nugetexe,
Directory.GetCurrentDirectory(),
string.Join(" ", args),
environmentVariables: new Dictionary<string, string>
{
{ "NUGET_SHOW_STACK", "false" }
});
// Assert
Assert.Contains(expected, result.Output + " " + result.Errors);
Assert.NotEqual(0, result.ExitCode);
}

This test invokes nuget.exe and validates its output by comparing the resulting strings.

Even if UseCultureAttribute is applied to the test method, the attribute only affects the test process itself. The spawned nuget.exe process still runs using the operating system's culture settings. As a result, any localized messages produced by nuget.exe may differ from the English strings expected by the test.

In other words, applying UseCultureAttribute to the test method does not necessarily guarantee that child processes use the same culture. Tests that validate the output of external processes can still fail under non-English system cultures.

@gekka
gekka requested a review from a team as a code owner July 21, 2026 17:46
@gekka
gekka requested review from Nigusu-Allehu and nkolev92 July 21, 2026 17:46
@dotnet-policy-service dotnet-policy-service Bot added the Community PRs created by someone not in the NuGet team label Jul 21, 2026
@gekka
gekka marked this pull request as draft July 25, 2026 05:02
@gekka
gekka marked this pull request as ready for review July 25, 2026 12:51
@gekka
gekka marked this pull request as draft July 26, 2026 02:07
@gekka
gekka marked this pull request as ready for review July 26, 2026 02:08
nkolev92
nkolev92 previously approved these changes Jul 28, 2026
@dotnet-policy-service dotnet-policy-service Bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Aug 6, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 30 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

Comment thread build/TestShared/ThreadCulture.cs Resolved
@dotnet-policy-service dotnet-policy-service Bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Aug 11, 2026
@Nigusu-Allehu Nigusu-Allehu self-assigned this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PRs created by someone not in the NuGet team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NuGet.Client tests include culture-dependent assertions

4 participants