Variable empty within It but given in Context

Hi *,

I have a Pester test with Test-ModuleManifest throwing an error now (worked before).
Very strange: it seems that it is an issue also connected to AppVeyor as it works locally.

The issue:

Context "Integrated Manifest Test" {
        Write-Host "ModuleManifestPath: $ModuleManifestPath"
        It 'Passes Test-ModuleManifest' {
            $null = Test-ModuleManifest -Path $ModuleManifestPath -ErrorAction Stop -WarningAction SilentlyContinue | Should -Not -Throw

This throws an error about -Path cant be bound as it is null.

Funny: my debugging output just outside of It is working fine and returning the right Path to my Manifest which is defined on top of all tests.

Any ideas?


Where is the $ModuleManifestPath defined ? did you change pester version and what is the pester version you use ?

Hi @kvprasoon

it is latest Pester on all systems (5.0.2 as I remember).

On AppVeyor and Azure Pipeline it is not working (both), locally (Win10) it is working.

I define the vars directly on top of my Test-Script, before first describe:

$moduleName = $env:BHProjectName
$ModuleManifestPath = "$($pwd)\$($moduleName).psd1"

The problematic test can be seen in my original post, within Context, before It the var has the content I want. Within It it seems to be empty.


Solved it: since v5 you have to put all in some BeforeAll{} context, otherwise it may not work.

Thanks for letting us know the cause.