Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Test hooks are run in default culture #5452

Copy link
Copy link

Description

@Lexy2
Issue body actions

Description

It looks like regardless of the level at which TUnit.Core.Executors.Culture attribute is applied (assembly, class, or test), the Before(Test) and After(Test) setup hooks are still run in the default machine culture, and it's changed only for the test thread.

This makes culture-specific hooks unusable. Those setup / cleanup methods just have to be called from within the test itself.

Expected Behavior

Hooks at the level where [Culture] attribute is applied are executed in the specified culture:

  • Before(Test) / After(Test) hooks use test-level culture, if not specified - class-level culture, if not specified - assembly-level culture, if not specified - default culture.
  • Before(Class) / After(Class) hooks use class-level culture, if not specified - assembly-level culture, if not specified - default culture.
  • Before(Assembly) / After(Assembly) hooks use assembly-level culture, if not specified - default culture.

Actual Behavior

Hooks are run in the default culture and the culture is only changed for the actual test method.

Steps to Reproduce

[Culture("de-DE")]
public class MyTest
{
    [Before(Test)]
    public void SetUp()
    {
        Console.WriteLine($"Running setup in thread {Thread.CurrentThread.ManagedThreadId} in {Thread.CurrentThread.CurrentCulture.Name}");
    }

    [Test]
    [Culture("fr-FR")]
    public void MyTestMethod()
    {
        Console.WriteLine($"Running test in thread {Thread.CurrentThread.ManagedThreadId} in {Thread.CurrentThread.CurrentCulture.Name}");
    }

    [Test]
    public void MyTestMethod2()
    {
        Console.WriteLine($"Running test 2 in thread {Thread.CurrentThread.ManagedThreadId} in {Thread.CurrentThread.CurrentCulture.Name}");
    }
}

TUnit Version

1.29.0

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Running setup in thread 20 in en-US
Running test in thread 24 in fr-FR
Running setup in thread 3 in en-US
Running test 2 in thread 25 in de-DE

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.