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)
- BeforeAll and AfterAll not invoked on skipped blocks when running test explicitly
- CodeCoverage.OutputEncoding ignored in xml encoding-attribute
- Invoke-Pester breaks on invalid CodeCoverage.OutputEncoding format
- TestResults.OutputEncoding option ignored
- Pester Should -Invoke -Scope "It" not working as expected HOT 1
- SkipRemainingOnFailure does not trigger on block failure
- Update how test registry entry is generated
- Improve Should-BeString assertion
- Fix Should-*Collection and their tests
- Make sure new assertion docs are in showing up on pester.dev
- Export Should-Invoke and Should-HaveParameter
- Output should result to Assert assertions
- Add soft assertions to new assertions
- Expose GlobalPluginData to all plugin steps
- Infinite loop for `FileInfo` and `DirectoryInfo` due to `Root` properties in `DirectoryInfo`. Should we restrict depth as a general fix in addition to specialcasing `DirectoryInfo` in `Get-DisplayProperty2`? HOT 1
- Measure Code Coverage for Pester
- `Get-Help Should-Be` will still show `Assert-Be`. We'll also need to modify `generate-command-reference.ps1` in docs-repo to rename files and title to match alias.
- `Get-EquivalencyOption` is not exposed, so unable to customize/no docs on expected hashtable. HOT 2
- Inconsistent behavior mocking external command between output verbosity 'Detailed' and 'Diagnostic' HOT 3
- Calling mock of Get-ChildItem with -File parameter fails on Linux 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.