Comments (3)
IIRC there's no difference between BeforeAll
and BeforeDisovery
regarding this behavior. So I'm not sure why one would work differently. Hard to troubleshoot without seeing the specific pipeline.
As mentioned the exit code will be positive (non-zero) when either block types fail. Ex.
# demoCI.ps1
param([switch]$FailFirst = $false)
$sbFailed = {
BeforeDiscovery {
throw 'oh nooo'
}
Describe 'Fail in BeforeDiscovery' {
It 'never runs' { 1 | Should -Be 1 }
}
}
$sbWorks = {
Describe 'Working file' {
It 'works' { 1 | Should -Be 1 }
}
}
$conf = New-PesterConfiguration
$conf.Run.ScriptBlock = @(if ($FailFirst) { $sbFailed }) + @($sbWorks)
# This exits the script/powershell with the exit code.
# Without it you'd usually have to check $LASTEXITCODE after Invoke-Pester and throw/exit if non-zero.
$conf.Run.Exit = $true
$conf.Output.Verbosity = 'None' # To shorten output
Invoke-Pester -Configuration $conf
Demo:
# Run with only successful container ($sbWorks)
> $proc = Start-Process pwsh -ArgumentList "-NoProfile -File ./demoCI.ps1" -PassThru -Wait
> $proc.ExitCode
0
# Run with failing container first ($sbFailed, $sbWorks)
> $proc = Start-Process pwsh -ArgumentList "-NoProfile -File ./demoCI.ps1 -FailFirst" -PassThru -Wait
> $proc.ExitCode
1 # This would usually fail a pipeline step unless configured to continue on error. YMMW depending on CI
from pester.
Thanks for the feature request.
This can lead to a false indication that the stage has passed successfully, even though it has encountered a failure.
$LASTEXITCODE
will always be non-zero when a container has failed, but you might have to check it in your step? Try the Run.Exit
option (or -CI
switch if you don't use advanced configuration) which will exit the powershell-prosess with the exit code.
It won't exit though, but it will skip the file where BeforeDiscovery
failed.
Implement a mechanism within Pester that checks the exit code of the BeforeDiscovery script and ensures that if it fails, the entire Pester test suite is aborted and the pipeline stage is marked as failed.
Not sure if you meant it this way, but checking exit codes from console applications etc. are unlikely to be supported. Atm. we only consider PowerShell exceptions and terminating errors to be a failure, which will stop the current file only.
from pester.
When I execute the tests and encounter a failure in the "beforeDiscovery" phase, the system reports a failed container with the following message:
Container failed: 1
/azp/_work/1/s/gov/tests/there.Tests.ps1
Interestingly, even though the tests within that container are not executed, the pipeline does not mark it as a failure. As a result, we won't be alerted to any potential issues with the tests unless we manually inspect them after each run.
However, I've observed that if a failure occurs in the "beforeAll" phase, it is correctly flagged as a test failure.
Is it possible to make "beforeDiscovery" cause the test to fail or take an action that flags it in the CI pipeline stage, so that the stage doesn't return as "all good"?
from pester.
Related Issues (20)
- Issues calling a Mock when a Mandatory attribute is included on a parameter HOT 3
- Should -HaveParameter -DefaultValue does not work for boolean types or integer value of 0 (regression) HOT 2
- Pester module warning 'CN=Jakub Jareš, O=Jakub Jareš, L=Praha, C=CZ' HOT 15
- Failure in Discovery when using different parameters across files HOT 3
- Select-Object and New-MockObject - Discarded PSObject HOT 2
- Mock CommandNotFoundException: Could not find Command Invoke-Sqlcmd HOT 4
- Bring back 'InconclusiveCount' property (or alternative) on returned Pester.Run object HOT 19
- I’m not a developer I run a nonprofit and a Pester Power Shell is running HOT 2
- Pester stopped working in vscode HOT 2
- v5.5 $____Pester.CurrentTest not populated in AfterEach HOT 4
- Missing timestamp from test suite attributes in junit xml export HOT 1
- Unbound container scriptblock unexpectedly runs in Pester scope HOT 10
- Pester 5.5 reports incorrect Skipped results for Pending and Inconclusive HOT 3
- BeOfType doesn't see types, loaded from a file with classes, but the "It" function - does HOT 3
- Refer to a script in a parent directory HOT 2
- Does somthing like @afterstep exist for Pester 4.6 with Invoke Gherkin HOT 1
- New-RandomTempRegistry: Test-Path : No more data is available HOT 2
- Provide a way to more easily modify a mocked parameter before comparing with a test value. HOT 3
- Error during handling of output-element within Write-NUnit3OutputElement HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pester.