Author Posts

September 29, 2015 at 8:07 am

I have a module lets call it root. Within the psd1 file i have a number of nested modules defined. I am trying to perform my unit tests using team city. I am copying all of the required modules to a local directory where I perform the tests. The problem is that the nested modules are not found when importing the root module as the local directory is not in PSModulePath. This is really by design, so if any one can tell me how to mock a module in the tested module node of the manifest to point at a relative location to the root module that would be great.

Hope this makes sense to some one.

Thanks.

September 30, 2015 at 5:52 am

Hi,

I don't know if anyone saw my earlier post. so I though that i would ask again. How can I test powershell modules that contain nested modules using Pester.

The Pester tests pass if the nested modules exist in the PSModulePath but fail if they do not.

Can anyone help?

Thanks

October 14, 2015 at 12:40 pm

You should be able to simple define a relative path in the NestedModules section of the .psd1 file, such as DependentModules\Module1\Module.psm1. Or you could import the module in code by the Import-Module cmdlet and use $PSScriptRoot to determine the path where your module resides. And then you can get to your module path either by using the standard *-Path cmdlets, such as Split-Path, or using the standand Windows relative path notation $PSScriptRoot\..\..\Modules.