Skip to content

Standard output from a failing OneTimeSetUp or OneTimeTearDown is never shown #1558

Done

Description

@OsirisTerje

When a OneTimeSetUp or OneTimeTearDown fails, standard output written in it (Console.WriteLine, TestContext.Out) never reaches the console, whatever ShowStdout or ConsoleOut is set to. That output is often exactly what explains the failure.

[TestFixture]
public class FailingSetupFixture
{
    [OneTimeSetUp]
    public void Setup()
    {
        TestContext.Out.WriteLine("STDOUT-FROM-ONETIMESETUP");
        throw new InvalidOperationException("Boom");
    }

    [Test]
    public void Test1() { }
}

dotnet test shows the Boom failure, but not STDOUT-FROM-ONETIMESETUP.

The cause: NUnit sends only TestContext.Progress and error output as live test-output events. Standard output is kept in the result, and for a suite that is the <output> element of the test-suite event. NUnitEventListener.TestFinished reads <output> for test cases, but NUnitEventListener.SuiteFinished never reads it. SuiteFinished only sends the buffered Progress and Error output (added in #1554), so standard output from a fixture's setup or teardown is dropped. There is no test result to attach it to either, so it doesn't show up in the logger's failure report.

Fix: in SuiteFinished, after the buffered output, send resultNode.Output as a Warning when the suite failed in SetUp or TearDown (the method already returns early otherwise) and ShowStdout is not None. It is sent as a Warning, like the buffered output, so dotnet test shows it without a detailed logger. Passing suites send nothing, so agent mode stays quiet.

ShowStdout Standard output of a failing OneTimeSetUp sent
All Yes
Failed Yes
None No

The docs for ShowStdout (nunit/docs#1324) describe the current behavior and need a one-line update when this is fixed.

🤖 Made by @OsirisTerje with Claude

Activity

  1. added this to the 6.4 milestone on Nov 30, 2026
  2. added a commit that references this issue on Nov 30, 2026
    ed7c28d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions