Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

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)

@msftclas
Copy link

msftclas commented Nov 3, 2016

Hi @SteveL-MSFT, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Steve Lee (POWERSHELL)). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

build.psm1 Outdated
{
if ($PSBoundParameters.Count -eq 0 -or $PSBoundParameters.ContainsKey("NUnitLog"))
{
$PesterFailure = Get-PSPesterFailures -NUnitLog $NUnitLog
Copy link
Collaborator

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 8, 2016

LGTM.
(Maybe add in docs how to use this?)

@SteveL-MSFT
Copy link
Member Author

@iSazonov good suggestion, I'll add something to the existing testing guidelines

* `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

Copy link
Collaborator

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?

Copy link
Member Author

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;
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

@TravisEz13 TravisEz13 Nov 15, 2016

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, will change

@TravisEz13 TravisEz13 added Area-Maintainers-Build specific to affecting the build WG-Quality-Test issues in a test or in test infrastructure labels Nov 11, 2016
added sample to using failure cmdlets
@vors vors closed this Nov 14, 2016
@vors vors reopened this Nov 14, 2016
* `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
Copy link
Collaborator

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.

@iSazonov
Copy link
Collaborator

In future, it would be good to use it to reduce logs on appveyor and travis-ci to only display failed tests.

@kilasuit
Copy link
Collaborator

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
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member Author

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

@iSazonov
Copy link
Collaborator

@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.

@kilasuit
Copy link
Collaborator

@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

@SteveL-MSFT
Copy link
Member Author

@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

@nohwnd
Copy link
Contributor

nohwnd commented Nov 18, 2016

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):
Invoke-Pester -PassThrough | Out-NUnitXml | Store-Xml | Parse-NUnitXml | Filter-Failures | Print-Fails

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 (-PassThru), filter test results to failures with Where, and then either use your print functions, or reuse the internal Pester print functions.

#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 44ms

Or 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.

@SteveL-MSFT
Copy link
Member Author

@nohwnd I think you're right, we can close this PR and wait for pester/Pester#645

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

Labels

Area-Maintainers-Build specific to affecting the build WG-Quality-Test issues in a test or in test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants