Skip
Skip on everything​
-Skip is now available on Describe and Context. This allows you to skip all the tests in that block and every child block.
Describe "describe1" {
Context "with one skipped test" {
It "test 1" -Skip {
1 | Should -Be 2
}
It "test 2" {
1 | Should -Be 1
}
}
Describe "that is skipped" -Skip {
It "test 3" {
1 | Should -Be 2
}
}
Context "that is skipped and has skipped test" -Skip {
It "test 3" -Skip {
1 | Should -Be 2
}
It "test 3" {
1 | Should -Be 2
}
}
}
Running tests from 1 files.
Running tests from 'C:\t\Skip.Tests.ps1'
Describing describe1
Context with one skipped test
[!] test 1 18ms
[+] test 2 52ms
Describing that is skipped
[!] test 3 12ms
Context that is skipped and has skipped test
[!] test 3 10ms
[!] test 3 10ms
Tests completed in 1.03s
Tests Passed: 1, Failed: 0, Skipped: 4, Inconclusive: 0, NotRun: 0
Conditional skip​
Evaluation of the skip-parameter is done as part of the Discovery-phase. This means you can also dynamically skip tests based on values available in that phase. Either as logic done in BeforeDiscovery or based on values passed into a parametrized test.
$sb = {
param($SkipFirst)
Describe 'My Describe Block' {
BeforeDiscovery {
$skipSecond = 1
}
It 'First Test' -Skip:$SkipFirst {
1 | Should -Be 1
}
It 'Second Test' -Skip:($skipSecond -eq 1) {
1 | Should -Be 1
}
It 'Third Test' {
1 | Should -Be 1
}
}
}
$container = New-PesterContainer -ScriptBlock $sb -Data @{ SkipFirst = $true }
$configuration = New-PesterConfiguration
$configuration.Run.Container = $container
$configuration.Output.Verbosity = 'Detailed'
Invoke-Pester -Configuration $configuration
Running tests from 1 files.
Running tests from '<ScriptBlock>'
Describing My Describe Block
[!] First Test 3ms
[!] Second Test 2ms
[+] Third Test 18ms
Tests completed in 206ms
Tests Passed: 1, Failed: 0, Skipped: 2, Inconclusive: 0, NotRun: 0
In certain scenarios you might need to mark a test as skipped or inconclusive during execution. This is possible using Set-ItResult. Be aware that setup and teardown-blocks will be executed, so use -Skip whenever possible.
Skipping the rest of a scope on failure​
Pester v6 can stop running the rest of a scope as soon as a test fails. This is useful when later tests can't meaningfully pass once an earlier one fails, for example when a shared resource failed to set up. Enable it with Run.SkipRemainingOnFailure:
| Value | Effect |
|---|---|
None (default) | Keep running every test. |
Run | Skip all remaining tests in the whole run after the first failure. |
Container | Skip the rest of the current file/container. |
Block | Skip the rest of the current Describe/Context block. |
$config = New-PesterConfiguration
$config.Run.Path = './tests'
$config.Run.SkipRemainingOnFailure = 'Block'
Invoke-Pester -Configuration $config
Remaining tests are also skipped when a block's setup or teardown fails.
[+] first passes 33ms
[-] second fails 12ms
[!] third would pass 1ms
[!] fourth would pass 0ms