-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
Exceptions thrown in Describe/Context BeforeAll or BeforeEach are undiagnosable. #1101
Comments
Thanks for reporting will have a look on this. |
@nohwnd I see these errors now as well after the last update of AppVeyor's |
@bergmeister all our linux an macos builds run fine on Travis, and I am running pester locally in docker just fine as well. Could you share your |
@nohwnd Ok, thanks, I opened a few PRs for your Assert module including Linux in AppVeyor. |
The errors are most likely filtered out by https://github.com/pester/Pester/blob/master/Functions/Output.ps1#L475 if you get rid of the pipeline it won't limit the output and will print the internals of Pester as well. Could you try that first to see if it gives relevant info please? |
@nohwnd OK, thanks, this is what I get now as an output:
|
ok, that did not help at all 🤣 |
I also see this issues showing up in AppVeyor Pester tests after the PowerShell 6.1 update in the recent Ubuntu image update. |
The error comes from here in PowerShell in case that helps as it could be an integration bug with PowerShell as well. |
I was able to reproduce it while running Appveyor with SSH access using a the following very simple test: Describe "describe" {
Context "context" {
try {
throw "test"
}
catch {
}
it "it" {
throw "inside it"
Write-Host "everything ok"
}
}
} PS /home/appveyor> Invoke-Pester -Script "./test.ps1"
Executing all tests in './test.ps1'
Executing script ./test.ps1
Describing describe
Context context
[-] Error occurred in Context block 62ms
ValidationMetadataException: The attribute cannot be added because variable Result with value would no longer be valid.
MethodInvocationException: Exception calling "AddTestResult" with "8" argument(s): "The attribute cannot be added because variable Result with value would no longer be valid."
Tests completed in 62ms
Tests Passed: 0, Failed: 1, Skipped: 0, Pending: 0, Inconclusive: 0 This is the PSVersionTable of the AppVeyor image PS /home/appveyor> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.1
PSEdition Core
GitCommitId 6.1.1
OS Linux 4.15.0-43-generic #46~16.04.1-Ubuntu SMP Fri Dec 7 13:31:08 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0 Without the catch block, Pester correctly shows the thrown exception inside the I also confirmed that running the same code on Mac OS X with the same PowerShell version does not result in the issue and instead shows the exception thrown inside the I expect that the Linux PowerShell build somehow has issues with handling exceptions which were captured. |
I tracked down the issue to Hashtable properties being case sensitive in the Appveyor Ubuntu (16.04) and Ubuntu1804 (18.04) images. I couldn't recreate the issue with the official Ubuntu docker images and the official steps from Microsoft to install PowerShell. The following highlights the issue in the Appveyor images: PS /home/appveyor> $test=@{result="result"}
PS /home/appveyor> $test.Result
PS /home/appveyor> $test.result
result Pester defines the Changing the property access to start with an uppercase would fix the issue. I'd be glad to contribute a pull request if someone can confirm that changing |
The issue is very likely caused by PowerShell/PowerShell#7761 |
Thanks everyone for trying to boil down the issue. I'll try the suggested changes by @ffeldhaus next Tuesday when I've got access to my dev environment again. Can you maybe also please give us a simple one line to change the LANG as described in the AppVeyor support issue. As per my comments above, I can reproduce the bug locally in my WSL (Ubuntu 18 but not 16 in my case for WSL) environment for my test suite, therefore I agree this is a general problem of Pester on PowerShell 6.1.1 that did not happen with PowerShell 6.0. However, a race condition or something environment specific might be involved in it as well since the bug does not repro on the hosted Ubuntu agent provided by Azure DevOps. |
I can confirm that changing the Pester hashtable access in the functions that @ffeldhaus points, it fixes the problem, I opened a PR in Pester since a publishing an updated Version of Pester might be quicker until the proper fix gets deployed in PowerShell 6.2 @FeodorFitsner However, setting LANG to
|
Yep, the language should be set "higher" in the process hierarchy. We are working on build agent update. Thanks for your patience guys. |
I just published the referenced PR as 4.4.4 (merged into master and cherrypicked to branch based on 4.4.3). 4.4.4 is the last stable version so AppVeyor users should be getting it unless they specified a version explicitly. Great work guys! Could someone test it out please ? @bergmeister ? |
@nohwnd I can confirm the fix is working! Thanks a lot for merging the pull request and creating a new release! Very much appreciated! @bergmeister Great job with the pull request! Here is the test which was previously returning the
|
@nohwnd Awesome, thanks for publishing it. It fixes the problems that I have seen, there seem to be new failures (again only on that special Ubuntu environment) that I have to look into but those failures are not a problem of Pester itself, it is a problem of my module now due to PowerShell being case sensitive. |
@bergmeister that sucks. Good luck solving it! |
Thanks, I could solve it in the end with only a few tweaks. P.S.: I re-ran Pester's own test suite on that environment and it only showed me 3 test failures after my PR (before it was 10) and the gist seems to be that Pester's mocking feature is not working in those environments (I guess again due to hashtable key casing mismatches either in Pester or PowerShell itself) but I am not using this feature so it is not a problem for me but might be worthwhile to point out to other people in those environments. |
1. Provide a general summary of the issue in the Title above
When a BeforeAll or BeforeEach block throws an exception, Pester error output doesn't include any information about the failure. Instead, a secondary exception is thrown due to the call to AddTestResult failing.
For example:
[-] Error occurred in Context block 3.4s
ValidationMetadataException: The attribute cannot be added because variable Result with value would no longer be valid.
MethodInvocationException: Exception calling "AddTestResult" with "8" argument(s): "The attribute cannot be added because variable Result with value would no longer be valid."
The same behavior occurs in both Describe and Context Before* blocks with the only difference being the block type (Context or Describe).
When this occurs, the only solution I've found is to edit the catch blocks in It.ps1 and Describe.ps1 and Write-Host the original failure details. Neither the console output nor the test result file contain this inforamation.
2. Describe Your Environment
Operating System, Pester version and PowerShell version:
3. Expected Behavior
If you're describing a bug, tell us what should happen.
The error details ($_) from the catch block should be reported and/or logged.
4.Current Behavior
The subsequent call to AddTestResult itself throws and this is the information reported; as indicated above.
5. Possible Solution
Have a solution in mind?
https://github.com/pester/Pester/wiki/Contributing-to-Pester has detailed instructions on how to contribute.
6. Context
How has this issue affected you? What are you trying to accomplish?
The text was updated successfully, but these errors were encountered: