pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.08k stars 470 forks source link

Pester 5 on Windows 7 "The member 'NoClobber' is not valid." #1847

Closed vquigley closed 2 years ago

vquigley commented 3 years ago

Question

I have a set of pester tests that work great in Win10 but I cannot get them to work in Windows 7.

I am sure I have the wrong version of a dependency but I cannot work it out and would love if someone could help me.

    #My code or output
Invoke-Pester -OutputFile Test.xml -OutputFormat NUnitXml -Tag "Only" -ExcludeTag "Issue-*", "Capture"

System.Management.Automation.ParseException: At C:\auto\ftw\ClientAutomation\PowerShellGet\DSC\Tests\Integration\MSFT_PS
Module.config.ps1:149 char:13
+             NoClobber    = $false
+             ~~~~~~~~~
The member 'NoClobber' is not valid. Valid members are
'AllowClobber', 'DependsOn', 'Ensure', 'Force', 'InstallationPolicy', 'MaximumVersion', 'MinimumVersion', 'Name', 'PsDsc
RunAsCredential', 'Repository', 'RequiredVersion', 'SkipPublisherCheck'.

At C:\auto\ftw\ClientAutomation\PowerShellGet\DSC\Tests\Integration\MSFT_PSModule.config.ps1:185 char:13
+             Version         = $Node.Module2_RequiredVersion
+             ~~~~~~~
The member 'Version' is not valid. Valid members are
'AllowClobber', 'DependsOn', 'Ensure', 'Force', 'InstallationPolicy', 'MaximumVersion', 'MinimumVersion', 'Name', 'PsDsc
RunAsCredential', 'Repository', 'RequiredVersion', 'SkipPublisherCheck'.

At C:\auto\ftw\ClientAutomation\PowerShellGet\DSC\Tests\Integration\MSFT_PSModule.config.ps1:186 char:13
+             NoClobber       = $false
+             ~~~~~~~~~
The member 'NoClobber' is not valid. Valid members are
'AllowClobber', 'DependsOn', 'Ensure', 'Force', 'InstallationPolicy', 'MaximumVersion', 'MinimumVersion', 'Name', 'PsDsc
RunAsCredential', 'Repository', 'RequiredVersion', 'SkipPublisherCheck'.

At C:\auto\ftw\ClientAutomation\PowerShellGet\DSC\Tests\Integration\MSFT_PSModule.config.ps1:204 char:13
+             Version         = $Node.Module2_RequiredVersion
+             ~~~~~~~
The member 'Version' is not valid. Valid members are
'AllowClobber', 'DependsOn', 'Ensure', 'Force', 'InstallationPolicy', 'MaximumVersion', 'MinimumVersion', 'Name', 'PsDsc
RunAsCredential', 'Repository', 'RequiredVersion', 'SkipPublisherCheck'.

At C:\auto\ftw\ClientAutomation\PowerShellGet\DSC\Tests\Integration\MSFT_PSModule.config.ps1:205 char:13
+             NoClobber       = $false
+             ~~~~~~~~~
The member 'NoClobber' is not valid. Valid members are
'AllowClobber', 'DependsOn', 'Ensure', 'Force', 'InstallationPolicy', 'MaximumVersion', 'MinimumVersion', 'Name', 'PsDsc
RunAsCredential', 'Repository', 'RequiredVersion', 'SkipPublisherCheck'.

At C:\auto\ftw\ClientAutomation\PowerShellGet\DSC\Tests\Integration\MSFT_PSModule.config.ps1:223 char:13
+             Version        = "[$($Node.Module2_MinimumVersion), $($No ...
+             ~~~~~~~
The member 'Version' is not valid. Valid members are
'AllowClobber', 'DependsOn', 'Ensure', 'Force', 'InstallationPolicy', 'MaximumVersion', 'MinimumVersion', 'Name', 'PsDsc
RunAsCredential', 'Repository', 'RequiredVersion', 'SkipPublisherCheck'.

At C:\auto\ftw\ClientAutomation\PowerShellGet\DSC\Tests\Integration\MSFT_PSModule.config.ps1:224 char:13
+             NoClobber      = $false
+             ~~~~~~~~~
The member 'NoClobber' is not valid. Valid members are
'AllowClobber', 'DependsOn', 'Ensure', 'Force', 'InstallationPolicy', 'MaximumVersion', 'MinimumVersion', 'Name', 'PsDsc
RunAsCredential', 'Repository', 'RequiredVersion', 'SkipPublisherCheck'.
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exc
eption)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProces
s)
   at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
   at System.Management.Automation.CommandProcessorBase.Complete()
at <ScriptBlock>, C:\auto\ftw\ClientAutomation\PowerShellGet\DSC\Tests\Integration\MSFT_PSModule.Integration.Tests.ps1:
line 18
at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\Pester\5.0.4\Pester.psm1: line 2724
at Invoke-File, C:\Program Files\WindowsPowerShell\Modules\Pester\5.0.4\Pester.psm1: line 2733
at Invoke-BlockContainer, C:\Program Files\WindowsPowerShell\Modules\Pester\5.0.4\Pester.psm1: line 2662
at Discover-Test, C:\Program Files\WindowsPowerShell\Modules\Pester\5.0.4\Pester.psm1: line 1295
at Invoke-Test, C:\Program Files\WindowsPowerShell\Modules\Pester\5.0.4\Pester.psm1: line 2195
at Invoke-Pester<End>, C:\Program Files\WindowsPowerShell\Modules\Pester\5.0.4\Pester.psm1: line 4524

Environment data Pester version : 5.0.4 C:\Program Files\WindowsPowerShell\Modules\Pester\5.0.4\Pester.psm1 PowerShell version : 5.1.14409.1005 OS version : Microsoft Windows NT 6.1.7601 Service Pack 1

Have also tried Pester 5.1.1

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     1.0.0.0    CimCmdlets                          {Export-BinaryMiLog, Get-CimAssociatedInsta
Manifest   1.0.1.0    Microsoft.PowerShell.Archive        {Compress-Archive, Expand-Archive}
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Comp
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Comp
Script     1.4.7      PackageManagement                   {Find-Package, Find-PackageProvider, Get-Pa
Script     5.0.4      Pester                              {Add-ShouldOperator, AfterAll, AfterEach, A
Script     2.2.5      PowerShellGet                       {Find-Command, Find-DscResource, Find-Modul
nohwnd commented 3 years ago

Please edit the post, and fix the formatting.

vquigley commented 3 years ago

Please edit the post, and fix the formatting.

Done. Sorry about that

asears commented 3 years ago

Seems to be Pester discovery on PowerShellGet. The NoClobber parameter is added after the fact, perhaps there's some difference in System.Management.Automation versions parsing this script, or a change to discovery between Pester 4 and 5?

https://github.com/PowerShell/PowerShellGet/blob/f1ddcb3bc602c61f9b98f79b1ab02b00331da8f5/DSC/Tests/Integration/MSFT_PSModule.config.ps1

If I'm reading this correctly, there was some change between versions of Automation to remove -NoClobber parameter. Pester is using an older version of this dependency.

https://github.com/PowerShell/PowerShell/commit/d59bd44329b581a56a208a31596f7c093b696826#diff-de5a92941c6af60243bddf234d26be7b0276e6063e4f889d66b834ce6ae6f3aa

fflaten commented 2 years ago

Closing as the tests are written for Pester 4 and were not compatible with Pester 5. There's dot-sourcing of config-data ++ in the root of the test-file which is later used in the tests -> Pester v4 code. You could also see it in the CI-pipeline.

Can't say why it worked on Win10, but on Win7 it's probably resolving to the built-in PowerShellGet module which doesn't have those parameters for the PSModule DSCResource. The CI adds paths to $env:PSModulePath ++ which would resolve to the locally built PowerShellGet. This is unrelated to Pester.