-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Added cmdlets to get Pester failures #2600
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
Conversation
|
Hi @SteveL-MSFT, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
build.psm1
Outdated
| { | ||
| if ($PSBoundParameters.Count -eq 0 -or $PSBoundParameters.ContainsKey("NUnitLog")) | ||
| { | ||
| $PesterFailure = Get-PSPesterFailures -NUnitLog $NUnitLog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get-PSPesterFailures should be replaced by Get-PSPesterFailure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
|
LGTM. |
|
@iSazonov good suggestion, I'll add something to the existing testing guidelines |
Fix spelling error.
| * `Get-PSPesterFailure` will parse the NUnit test result log and return PowerShell objects for each failure so you can do additional filtering, sorting, grouping, etc... | ||
| * `Format-PSPesterFailure` will call `Get-PSPesterFailure` if no parameters are provided and show just the failures at the console simliar to what Pester displays | ||
| * `Format-PSPesterFailure` will call `Get-PSPesterFailure` if no parameters are provided and show just the failures at the console similar to what Pester displays | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add call samples as above for Start-PSPester?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
| foreach ($failureTest in $failureTests) | ||
| { | ||
| $totalFailures++ | ||
| $failure = New-Object -TypeName PSCustomObject -Property @{SuiteName=$failureSuite.Name;TestDescription=$failureTest.Description; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the properties could be more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TravisEz13 do you have a specific suggestion as it seems readable to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guidance developed in the DSC Resource project is to have each name-value pair on a new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, will change
added sample to using failure cmdlets
| * `Format-PSPesterFailure` will call `Get-PSPesterFailure` if no parameters are provided and show just the failures at the console similar to what Pester displays | ||
|
|
||
| ```PowerShell | ||
| Start-PSPester # summary shows failures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a typo and comment must be on a new line.
|
In future, it would be good to use it to reduce logs on appveyor and travis-ci to only display failed tests. |
|
Only query that I would has is should these functions be added to the PowerShell repo or would it make more sense that they be added directly into Pester? My rational behind adding to Pester is that I can see use cases for them being used outside of just testing the PowerShell Code base so to me it would make more sense for these to be added to Pester. |
|
|
||
| For example, to run all the Pester tests for CI (assuming you are at the root of the PowerShell repo): | ||
| ``` | ||
| ```PowerShell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MINOR: lowercase powershell works more universally, but this will work for now on GitHub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TravisEz13 as a maintainer, you can make small edits directly into this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make this change since I'm already updating this PR
|
@kilasuit Your proposal looks very good. I think it would be better to create a Issue in Pester repo and don't block this PR. |
|
@iSazonov - As much as I agree with your suggestion, I do feel that the onus to do so would lie with @SteveL-MSFT considering that this is his PR & his code etc etc |
|
@kilasuit I created pester/Pester#645 as a feature request to Pester. I think this could be solved in a number of ways and this PR was specifically to solve a problem I encountered where we have a large number of tests for PowerShell (and growing!) and needed an easy way to just see the failures so I can investigate before pushing my changes |
|
Is this the best way to do it? I think you are tapping too late in the pipeline. The pipeline is something like this (pseudo code): You are at the end, looking at the nUnit report in XML. Instead you can tap into the pipeline right after Invoke-Pester. Get the results as a PSObject ( #store the results in a variable
$results = invoke-pester -passthru
#get first successful result (you'd do -ne "Success")
$result = $results.TestResult | Where {$_.Result -eq "Passed"} | Select -first 1
#get reference to internal Pester print function
#(see output.ps1 in Pester, for other output functions)
$writePesterResult = &(Get-Module Pester) {Get-Command Write-PesterResult}
#print the result
&$writePesterResult $result
#outputs: [+] adds positive numbers 44msOr just wait for us to put it directly in Pester. 😃 I just wanted to highlight what is in my opinion a better way to approach this problem. |
|
@nohwnd I think you're right, we can close this PR and wait for pester/Pester#645 |
Get-PSPesterFailure will parse the Pester log from start-pspester and extract the failures as objects
Format-PSPesterFailure will format the failures similar to output from Pester (you can use directly without Get-PSPesterFailure)