pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.

Home Page:https://pester.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BeforeAll and AfterAll not invoked on skipped blocks when running test explicitly

fflaten opened this issue · comments

Checklist

What is the issue?

BeforeAll and AfterAll are not executed on skipped blocks when explicitly running a test, e.g. using Filter.Line option. See highlighted lines below which are missing.

Expected Behavior

Discovery found 2 tests in 23ms.
Filter 'Line' set to ('C:\Users\Frode\Git\Pester/demoBlockSkip.tests.ps1:18').
Filters selected 1 tests to run.
Discovery: Test discovery finished.
Running tests.

Running tests from 'C:\Users\Frode\Git\Pester\demoBlockSkip.tests.ps1'
Before ALL ROOT
+Before ALL -A
+Before ALL -B
Describing A
 Describing B
Before EACH -A
Before EACH -B
This is test 2
After EACH -B
After EACH -A
   [+] Test 2 27ms (24ms|4ms)
+After ALL -B
+After ALL -A
After ALL ROOT
Tests completed in 101ms
Tests Passed: 1, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 1

Steps To Reproduce

demoBlockSkip.tests.ps1

BeforeAll { Write-Host 'Before ALL ROOT' }
AfterAll { Write-Host 'After ALL ROOT' }

Describe 'A' -Skip {
    BeforeAll { Write-Host 'Before ALL -A' }
    AfterAll { Write-Host 'After ALL -A' }
    BeforeEach { Write-Host 'Before EACH -A' }
    AfterEach { Write-Host 'After EACH -A' }

    It 'Test 1' -Skip { Write-Host 'This is test 1' }

    Describe 'B' {
        BeforeAll { Write-Host 'Before ALL -B' }
        AfterAll { Write-Host 'After ALL -B' }
        BeforeEach { Write-Host 'Before EACH -B' }
        AfterEach { Write-Host 'After EACH -B' }

        It 'Test 2' -Skip { Write-Host 'This is test 2' }
    }
}

demoBlockSkip.ps1

$conf = New-PesterConfiguration
$conf.Run.Path = "$PSScriptRoot/demoBlockSkip.tests.ps1"
$conf.Filter.Line = "$PSScriptRoot/demoBlockSkip.tests.ps1:18"
Invoke-Pester -Configuration $conf

Describe your environment

Pester version : 5.6.0-beta1 C:\Users\Frode\Documents\PowerShell\Modules\pester\5.6.0\Pester.psm1
PowerShell version : 7.4.2
OS version : Microsoft Windows NT 10.0.22631.0

Possible Solution?

Will be fixed by #2447 by setting Skip to false on blocks with child blocks/tests that will be executed. The logic needs to occur after evaluating all tests for explicit include recursively as tests usually inherit skip from parent block.