Skip to content
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

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

Closed
3 tasks done
fflaten opened this issue May 13, 2024 · 0 comments · Fixed by #2447
Closed
3 tasks done

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

fflaten opened this issue May 13, 2024 · 0 comments · Fixed by #2447
Labels

Comments

@fflaten
Copy link
Collaborator

fflaten commented May 13, 2024

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.

@fflaten fflaten added the Bug label May 13, 2024
@fflaten fflaten changed the title BeforeAll and AfterAll not invoked when running skipped test explicitly BeforeAll and AfterAll not invoked on skipped blocks when running test explicitly May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant