Skip to content

Feature: Add a -Reason parameter when using the -Skip switch  #2049

@AlonGvili

Description

@AlonGvili

Summary of the feature request

Hey, I wonder if you can add What is the reason a test was skipped

the current return object you will get if you using -PassThru doesn't contain any info on this
maybe you can add parameter name -Reason 'the reason it skipped'

PS D:\Github\pwshchakraui> $results.Skipped[0]             


Name              : Has help comment block
Path              : {New-Tab, Comment Base Help, Has help comment block}
Data              :
ExpandedName      : Has help comment block
ExpandedPath      : New-Tab.Comment Base Help.Has help comment block
Result            : Skipped
ErrorRecord       : {}
StandardOutput    :
Duration          : 00:00:00.0054751
ItemType          : Test
Id                :
ScriptBlock       :
                                    $FilePath | Should -FileContentMatch "<#"
                                    $FilePath | Should -FileContentMatch "#>"

Tag               :
Focus             : False
Skip              : True
Block             : [!] Comment Base Help
First             : True
Last              : False
Include           : False
Exclude           : False
Explicit          : False
ShouldRun         : True
StartLine         : 9
Executed          : True
ExecutedAt        : 8/14/2021 11:43:21 AM
Passed            : True
Skipped           : True
UserDuration      : 00:00:00
FrameworkDuration : 00:00:00.0054751
PluginData        :
FrameworkData     :

How should it work? (optional)

Describe "describe1" {
    Context "with one skipped test" {
        It "test 1" -Skip -Reason 'i want it to skip' {
            1 | Should -Be 2
        }

        It "test 2" {
            1 | Should -Be 1
        }
    }

    Describe "that is skipped" -Skip -Reason 'i want it to skip all the tests' {
        It "test 3" {
            1 | Should -Be 2
        }
    }

    Context "that is skipped and has skipped test" -Skip -Reason 'i want all the It tests to skip' {
        It "test 3" -Skip {
            1 | Should -Be 2
        }

        It "test 3" {
            1 | Should -Be 2
        }
    }
}

So the return object will look something like this.

Name              : Has help comment block
Path              : {New-Tab, Comment Base Help, Has help comment block}
Data              :
ExpandedName      : Has help comment block
ExpandedPath      : New-Tab.Comment Base Help.Has help comment block
Result            : Skipped
ErrorRecord       : {}
StandardOutput    :
Duration          : 00:00:00.0054751
ItemType          : Test
Id                :
ScriptBlock       :
                                    $FilePath | Should -FileContentMatch "<#"
                                    $FilePath | Should -FileContentMatch "#>"

Tag               :
Focus             : False
Skip              : True
Block             : [!] Comment Base Help
First             : True
Last              : False
Include           : False
Exclude           : False
Explicit          : False
ShouldRun         : True
StartLine         : 9
Executed          : True
ExecutedAt        : 8/14/2021 11:43:21 AM
Passed            : True
Skipped           : True
SkippedReason  : I want it to skip
UserDuration      : 00:00:00
FrameworkDuration : 00:00:00.0054751
PluginData        :
FrameworkData     :

Activity

fflaten

fflaten commented on Jul 17, 2022

@fflaten
Collaborator

If implemented, NUnit3-console stores it in the xml-report as both a property and reason-element:

<test-case ....>
  <properties>
    <property name="_SKIPREASON" value="Test needs modification" />
  </properties>
  <reason>
    <message><![CDATA[Test needs modification]]></message>
  </reason>
</test-case>
corbob

corbob commented on Dec 6, 2024

@corbob

If someone were to submit a PR to implement this, is it something that the project would be interested in reviewing and merging? This is a feature that I would very much like to see, and would be willing to attempt to implement.

linked a pull request that will close this issue on Jan 9, 2025
corbob

corbob commented on Jan 9, 2025

@corbob

I've taken a stab at implementing something for this in #2607, as well as updating Set-ItResult so that it's reasons are also exported to the rest results. It is currently WIP as I have to cleanup the commit messages, and remove some extraneous files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @fflaten@corbob@AlonGvili

      Issue actions

        Feature: Add a -Reason parameter when using the -Skip switch · Issue #2049 · pester/Pester