-
-
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
Script scope variables not defined for tests #2028
Comments
So I've fixed the original issue, but had to duplicate code because some variables were needed in both the discovery and test phases. Now I'm hitting a strange problem where our Pester tests call a module which calls [-] UseConsistentIndentation.When a multi-line command is given.Should indent properly after line continuation (backtick) character 231ms (225ms|6ms)
CommandNotFoundException: The term 'Should' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at Test-CorrectionExtentFromContent, C:\projects\psscriptanalyzer\Tests\PSScriptAnalyzerTestHelper.psm1:49
at <ScriptBlock>, C:\projects\psscriptanalyzer\Tests\Rules\UseConsistentIndentation.tests.ps1:286 Link to the test code and the helper function definition. This only happens in PowerShell 4; the tests all pass and run correctly in PS 5.1 and 7 on all platforms. |
I managed to find a workaround for this: PowerShell/PSScriptAnalyzer@1f8f793. |
Thanks. Probably same as #1831. Can you reproduce consistently? Possible to run this in a different CI or server with PSv4? Both issues point to Appveyor WMF4 image it seems. |
Sounds like this is indeed #1831. I don't have easy access to another instance unfortunately. |
General summary of the issue
PSScriptAnalyzer migrated to Pester 5 about a year ago, but recently we've seen some new test failures in CI.
I wasn't able to reproduce the issue in my local clone, and my suspicion is that my local Pester version (5.1-rc1) doesn't have the issue.
In CI we seem to be using 5.0.2.
I'm working on the fix in PowerShell/PSScriptAnalyzer#1697.
Essentially:
BeforeAll
blockIt looks like we're using Pester 5.0.2 in PS 4 and I'm wondering what the right solution is here and why it might be behaving differently across different platforms.
The text was updated successfully, but these errors were encountered: