pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.08k stars 470 forks source link

Pester 5.5 reports incorrect Skipped results for Pending and Inconclusive #2413

Closed Scal-Human closed 8 months ago

Scal-Human commented 8 months ago

Checklist

What is the issue?

The results reported by Pester are incorrect when using Set-ItResult. It reports Skipped while expecting Pending or Inconclusive.

Expected Behavior

When the Set-ItResult is used the result should be the given one (Pending or Inconclusive).

Steps To Reproduce

Having

Describe 'Pester <Version>' -ForEach @(
    @{ Version = '{0} on {1} with PowerShell {2}' -f (Get-Module Pester).Version, [Environment]::OSVersion, $PSVersionTable.PSVersion }
) {
    Context 'Correct results' {
        It 'Passes'             { 'Ok' | Should -Not -Be $Null }
        It 'Fails'              { Throw 'Failing' }
        It 'Is skipped 1' -Skip { 'Will be skipped' }
        It 'Is skipped 2'       { Set-ItResult -Skip }
    }
    Context 'Incorrect results' {
        It 'Is pending 1'       { Set-ItResult -Pending }
        It 'Is pending 2'       { Set-ItResult -Pending -Because 'With reason' }
        It 'Is inconclusive 1'  { Set-ItResult -Inconclusive }
        It 'Is inconclusive 2'  { Set-ItResult -Inconclusive -Because 'With reason' }
    }
}

and calling

(Invoke-Pester -Configuration (@{ Output = @{ Verbosity = 'Detailed' }; Run = @{ PassThru = `$True; Path = 'Pester-Tests.ps1' } })).Tests | Format-Table Result, ExpandedPath, ErrorRecord

Describe your environment

Output is

Pester v5.5.0

Starting discovery in 1 files.
Discovery found 8 tests in 224ms.
Running tests.

Running tests from 'C:\Project\Poc\Source\PowerShellTest\Deck\Pester-Tests.ps1'
Describing Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0
 Context Correct results
   [+] Passes 125ms (87ms|38ms)
   [-] Fails 9ms (7ms|1ms)
    RuntimeException: Failing
    at <ScriptBlock>, C:\Project\Poc\Source\PowerShellTest\Deck\Pester-Tests.ps1:6
   [!] Is skipped 1 3ms (0ms|3ms)
   [!] Is skipped 2 is skipped 12ms (11ms|1ms)
 Context Incorrect results
   [!] Is pending 1 is skipped, because PENDING 8ms (3ms|5ms)
   [!] Is pending 2 is skipped, because PENDING: With reason 8ms (3ms|5ms)
   [!] Is inconclusive 1 is skipped, because INCONCLUSIVE 3ms (2ms|1ms)
   [!] Is inconclusive 2 is skipped, because INCONCLUSIVE: With reason 3ms (2ms|1ms)
Tests completed in 947ms
Tests Passed: 1, Failed: 1, Skipped: 6 NotRun: 0

passthru content is

Result  ExpandedPath                                                                                                ErrorRecord
------  ------------                                                                                                -----------
Passed  Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0.Correct results.Passes              {}
Failed  Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0.Correct results.Fails               {Failing}
Skipped Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0.Correct results.Is skipped 1        {}
Skipped Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0.Correct results.Is skipped 2        {is skipped}
Skipped Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0.Incorrect results.Is pending 1      {is skipped, because PENDING}
Skipped Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0.Incorrect results.Is pending 2      {is skipped, because PENDING: With reason}
Skipped Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0.Incorrect results.Is inconclusive 1 {is skipped, because INCONCLUSIVE}
Skipped Pester 5.5.0 on Microsoft Windows NT 10.0.19045.0 with PowerShell 7.4.0.Incorrect results.Is inconclusive 2 {is skipped, because INCONCLUSIVE: With reason}

Possible Solution?

None

fflaten commented 8 months ago

Hi. This was a known breaking changes in v5 to be considered in the future.

Inconclusive and Pending states are currently no longer available, -Pending and -Inconclusive are translated to -Skip both on test blocks and when using Set-ItResult

A PR is currently being reviewed to implement Inconclusive and deprecate Pending, see #2405. 🙂

Scal-Human commented 8 months ago

Hi, yes, I saw it but I was fooled by the deprecation aspect. I looked at the code and saw nothing concerning Inconclusive except the title. It is important to preserve the Inconclusive while indeed the Pending is less useful. Thanks, Have a nice day

fflaten commented 8 months ago

It is important to preserve the Inconclusive while indeed the Pending is less useful.

👍 Closing as kinda duplicate of #2400 with the mentioned PR. Thanks for using Pester. Have a great week.