vexx32 / PSKoans

A simple, fun, and interactive way to learn the PowerShell language through Pester unit testing.
GNU General Public License v3.0
1.73k stars 176 forks source link

Powershell Core 7.1.2 Exception importing PSKoans module #426

Closed rogerramtech closed 3 years ago

rogerramtech commented 3 years ago

Describe "Module Bug or Issue"

No longer able to import PSKoans module. Pester imports no problem. 'Exception: Assertion operator name 'Be' has been added multiple times.`

Context "The Problem"

Using PS Core 7.1.2 on MACOS Big Sur.

install-module Pester
install-module PSKoans -Force

Exception: Assertion operator name 'Be' has been added multiple times.

Was working previously before upgrade to Big Sur. I am not certain that this was the catalyst though. may have worked afterwards also. Currently cannot load the module anymore. Tried rolling back to PSCore 7.1.1 with same outcome. Also happened previously. Prior to loading BigSur, but went away with no apparent changes to system.

Context "Expected Behavior"

Should load module and work correctly.

Context "Additional Information"

Get-Module -Name PSKoans -ListAvailable |
    Select-Object -Property Name, Version

Name    Version
----    -------
PSKoans 0.67.1

$PSVersionTable | Out-String

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Darwin 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec  2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
vexx32 commented 3 years ago

Weird. This is happening on a completely fresh shell as well? Just importing the module?

What version(s) of Pester do you have installed?

rogerramtech commented 3 years ago

Yes. Happening in Fresh shell. Restarted entire computer even.

gmo | select Name, Version

Name                              Version
----                              -------
Microsoft.PowerShell.Management   7.0.0.0
Microsoft.PowerShell.Utility      7.0.0.0
Pester                            5.1.1
PowerShellEditorServices.Commands 0.2.0
PowerShellEditorServices.VSCode   0.2.0
PSReadLine                        2.1.0

Interestingly, I have 2 shells running. 1 in iTerm2 and one in the VS Code Terminal. When I created the issue before, neither would work. Immediately after creating the issue, I ran ipmo PSKoans -Verbose and it loaded! No issue. However the one running in the Code Terminal will not import still.

ipmo PSKoans -Debug -Verbose             

VERBOSE: Loading module from path '/Users/xXxX/.local/share/powershell/Modules/PSKoans/0.67.1/PSKoans.psd1'.
Exception: Assertion operator name 'Be' has been added multiple times.

Previously both would work fine, and I'm up to Constructs and Patterns. Started happening roughly after finishing the Katas. Weird indeed.

rogerramtech commented 3 years ago

Temporary Solution

Looks to be a intermittent Pester version incompatibility issue. Loaded 4.10.1 and all is well again. Thanks for the hint. ;-)

Other instance of pwsh on same device is working with Pester 5.1.1. ¯_(ツ)_/¯

(Long hand for clarity, for anyone else having the issue)

Remove-Module -Name Pester
Install-Module -Name Pester -RequiredVersion 4.10.1
Import-Module -Name Pester -RequiredVersion 4.10.1
Import-Module -Name PSKoans
Get-Module | Select-Object -Property Name, Version         

Name                              Version
----                              -------
DummyTypes                        0.0
Microsoft.PowerShell.Management   7.0.0.0
Microsoft.PowerShell.Utility      7.0.0.0
PackageManagement                 1.4.7
Pester                            4.10.1
PowerShellEditorServices.Commands 0.2.0
PowerShellEditorServices.VSCode   0.2.0
PowerShellGet                     2.2.5
PSKoans                           0.67.1
PSReadLine                        2.1.0

$PSVersionTable | Out-String

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Darwin 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec  2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
vexx32 commented 3 years ago

That's really weird... Not really sure what would cause that, other than probably Pester being loaded multiple times for some reason. (Especially since PSKoans requires at least v5 of Pester anyway in its current version. Mind you, I can't recall if we;'ve published that version just yet. I was waiting on some additional things from Pester itself that haven't been put together quite yet in v5.)

vexx32 commented 3 years ago

I'll close this for now as it seems to be resolved and there is something of a solution. If you see it again, feel free to update this issue and maybe there's something we can do here in future when we know more.

rogerramtech commented 3 years ago

Thanks! I appreciate the nudge in the right direction and assistance. Pester does not appear to be loaded multiple times according to Pwsh, but... Who knows. Any idea on time frame of v5 compatible version?

vexx32 commented 3 years ago

I'd like to get a few more things sorted before I publish it, but the current main branch here is v5 compatible, from memory. Just some loose ends to tie up, really. The main thing that made me hesitate is that due to how one of the functions works, we can't test its functionality using Pester itself, which is a bit annoying, I'd like to confirm it works correctly, after all...

But perhaps it's waited long enough 🙂