I have created a "Powershell Module Project" within Visual Studio 2015 and wrote some functions for the module. When I make changes to the .psm1
file and try to unit test these changes with the Pester framework (.test.ps1
file) the new changes are not applied during the test. This happens in Visual Studio 2015 and Visual Studio 2017.
I've tried:
The only solution I've found so far is to reopen the IDE.
Where might this issue originate from and is there any other solution to it?
When you change a PowerShell module that has already been loaded, those changes don't automatically apply to the currently running PowerShell session because the module has been loaded in to memory (and this remains true even if you manually run Import-Module <modulename>
as PowerShell sees the module is already loaded and does nothing).
The workaround is to either use Remove-Module
first and then reload it with Import-Module
, or use Import-Module <modulename> -Force
.
You could add either of these solutions to the top of your Pester test file to ensure it's always reloading the module before testing it.