You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Testing Platform overwriting/removing user console output #4425
publicclassTests{[Before(TestSession)]publicstaticasyncTaskBeforeTestSession(){Console.WriteLine($"BeforeTestSession started at {DateTime.Now}");awaitTask.Delay(TimeSpan.FromSeconds(5));Console.WriteLine($"BeforeTestSession ended at {DateTime.Now}");}[Before(Assembly)]publicstaticasyncTaskBeforeAssembly(){Console.WriteLine($"BeforeAssembly started at {DateTime.Now}");awaitTask.Delay(TimeSpan.FromSeconds(5));Console.WriteLine($"BeforeAssembly ended at {DateTime.Now}");}[Test]publicvoidTest1(){Console.WriteLine($"Executing Test at {DateTime.Now}");}}
If you just do a dotnet run on the CLI, you'll have to be quick, but when it starts to show "BeforeAssembly started", you'll see it render really quickly, but then it'll be removed and overwritten by the rendering of the [✓0/x0/↓0] ConsoleApp5.dll (net9.0|x64).
I guess this is related to the new interactive output and showing running tests etc. But overwriting user output means they may lose visibility of important information.
The before and after on assembly are not displayed at all while the test session is.
From what I saw the Before assembly happens really quickly, but then immediately after TUnit will pick up the first test and send a test node update with InProgressState, which is probably causing the output terminal to update and re-render.
This is bound to happen when the progress is enabled, and we write to the screen from a different place, e.g from the test directly without capturing the output.
There is no way around unless we substitute the Console.Out with one that is respecting the lock we have in progress reporting.
Jakub Jareš (@nohwnd) I didn't look into how the progress-aware terminal works, but I think at whatever point the position of writing is determined, to the end of writing, should be wrapped in lock (Console.Out).
In short, we can already lock on Console.Out which is implicitly the same lock as user writing to console. So, no need to substitute Console.Out with one that respects our lock. Instead we will respect the lock used by runtime's SyncTextWriter for the default console.
I reproduced this with the versions in the report: with progress enabled, only two of the five hook messages remained visible. Routing the same messages through MTP's IOutputDevice using TextOutputDeviceData kept all five visible without disabling progress.
This appears to be a limitation of writing directly to the console while the cursor-based progress renderer is active: a write between redraws moves the cursor, so the next redraw can erase user output. Locking Console.Out around progress rendering would not prevent that. For frameworks such as TUnit, the better fix is to send live hook messages through MTP's output device.
As a workaround, --no-progress preserved all five messages on MTP 1.4.3. On TUnit 1.87.12 / MTP 2.5.3, --output detailed --show-stdout all --progress off also kept them visible live.
Activity
Evangelink commentedon Dec 22, 2024
I'm off for now so just dumping my thoughts for when I return. We need to try if the behavior is the same when using IOutput to display messages.
Evangelink commentedon Jan 9, 2025
I won't be able to investigate more right now but dumping more info of trying to repro:
The before and after on assembly are not displayed at all while the test session is.
Evangelink commentedon Jan 9, 2025
Jakub Jareš (@nohwnd) What's your opinion and recommendations here?
thomhurst commentedon Jan 9, 2025
From what I saw the Before assembly happens really quickly, but then immediately after TUnit will pick up the first test and send a test node update with InProgressState, which is probably causing the output terminal to update and re-render.
nohwnd commentedon Jan 9, 2025
This is bound to happen when the progress is enabled, and we write to the screen from a different place, e.g from the test directly without capturing the output.
There is no way around unless we substitute the Console.Out with one that is respecting the lock we have in progress reporting.
#3491
Similarly this can happen when we run in child process and parent process (testhost controller writes to the screen).
Youssef1313 commentedon Jan 15, 2025
Jakub Jareš (@nohwnd) I didn't look into how the progress-aware terminal works, but I think at whatever point the position of writing is determined, to the end of writing, should be wrapped in
lock (Console.Out).In short, we can already lock on
Console.Outwhich is implicitly the same lock as user writing to console. So, no need to substitute Console.Out with one that respects our lock. Instead we will respect the lock used by runtime's SyncTextWriter for the default console.Evangelink commentedon Nov 24, 2026
I reproduced this with the versions in the report: with progress enabled, only two of the five hook messages remained visible. Routing the same messages through MTP's
IOutputDeviceusingTextOutputDeviceDatakept all five visible without disabling progress.This appears to be a limitation of writing directly to the console while the cursor-based progress renderer is active: a write between redraws moves the cursor, so the next redraw can erase user output. Locking
Console.Outaround progress rendering would not prevent that. For frameworks such as TUnit, the better fix is to send live hook messages through MTP's output device.As a workaround,
--no-progresspreserved all five messages on MTP 1.4.3. On TUnit 1.87.12 / MTP 2.5.3,--output detailed --show-stdout all --progress offalso kept them visible live.