Skip to content

Pester crashes due to native command output in BeforeAll #2655

@SteveL-MSFT

Description

@SteveL-MSFT

Checklist

What is the issue?

Within BeforeAll{} if running a native command and it emits output to STDOUT, it can cause Pester to have an unhandled exception later.

Expected Behavior

Test should run and Pester should not have unhandled exception

Steps To Reproduce

In this test script within the BeforeAll{} it runs winrm quickconfig -quiet -force, despite -quiet, the command runs net start winrm which itself emits that WinRM service is already running on this machine. to STDOUT. This is captured by Pester and during execution, at this line where it's adding a "container", $i happens to be the output string from above and Pester fails with:

System.Management.Automation.MethodException: Cannot find an overload for "Add" and the argument count: "1".
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at Invoke-Pester<End>, C:\Users\slee\OneDrive - Microsoft\Documents\PowerShell\Modules\pester\5.7.1\Pester.psm1: line 4985
at <ScriptBlock>, <No file>: line 1

Fix in the test was to redirect the output to $null, but this wasn't obvious and was working with previous version of Pester 5.

Describe your environment

This is with Pester 5.7.1

Possible Solution?

In the test, redirect the native command output to $null

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions