Pester,nested modules and teamcity

This topic contains 2 replies, has 2 voices, and was last updated by  nohwnd 2 years, 8 months ago.

  • Author
  • #30223

    Stephen Yeadon

    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.


  • #30271

    Stephen Yeadon


    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?


  • #30839


    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.

You must be logged in to reply to this topic.