-
-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invoke-Pester reports negative exit code, despite: Exit = $false #2338
Comments
Hi. Do you get an error message? Failed tests would set a positive exitcode. |
Test 4 actually sets the exit code, you're just not seeing it because you invoked Pester through a script.
If you write
It does honor the option. Docs says Summary:
|
Adding to fflaten answer, the exit code is figured out here: https://github.com/pester/Pester/blob/main/src/Main.ps1#L1294-L1316 Setting the exit code to non-zero when tests fail even when we won't exit explicitly is by design. You don't always want to To work around your issue you can ignore Pester exit code by doing the same thing we do to ignore any previous exit codes, you set: $global:LASTEXITCODE = 0 |
Checklist
What is the issue?
I use Pester in my Packer build process, to check if all programs I wanted to install, are existing in the master image. Even if tests fail, I need the packer build to continue. As of now, as soon as one test fails, packer reports the number of failed tests as exit code. This is interpreted as an error by Packer and the build process breaks.
As to my understanding, the Pester Configuration for Exit and Throw should handle that:
I've set that to
$false
, see code below. But I've also tested true, and it always reboots the number of failed tests. May I do something wrong, but it doesn't seem to work as I would expect.Now I help myself, as the last line in my Pester script is just
exit 0
, which works around that issue.(I interpret the errors itself later in the pipeline, I want it to break after all, but not at this step of the build pipeline.)
Expected Behavior
I would expect Pester configuration to include a switch, to turn on or off, if the number of failed tests is reported as an exit code or not. Like the documentation already suggests -> https://pester.dev/docs/commands/New-PesterConfiguration
Steps To Reproduce
Describe your environment
Windows 10 22H2 Enterprise Multi User on Azure
PowerShell 7.3.x installed
Latest Pester 5.x from PowerShell Gallery
During my build pipeline, it's logged as:
Possible Solution?
The text was updated successfully, but these errors were encountered: