Skip to content

Pester.BeforeContainer.ps1 is not applied during Run.SkipRun discovery #3008

Description

@nohwnd

Run.SkipRun runs discovery and returns the tree without executing tests. That is the path the VS Code Test Explorer uses to populate.

Pester.BeforeContainer.ps1 is not applied on that path. A file whose discovery depends on the setup, for example one that calls a helper to build -ForEach data or to compose test names, discovers fine in a normal run and comes back empty, or fails with "The term '...' is not recognized", when only discovery is requested.

Repro shape

# <root>/Pester.BeforeContainer.ps1
BeforeDiscovery { $script:Cases = 1..3 }

# <root>/tests/Some.Tests.ps1
Describe 'd' {
    It 'case <_>' -ForEach $Cases { }
}

Normal run discovers 3 tests. Run.SkipRun = $true discovers 0.

Note

The batch discovery in that path runs all containers in one call, so applying the chain per container needs care: the files differ per container after #2993, and the setup has to reach the container's own scope the same way it does in a normal run rather than being dot-sourced once for the whole batch.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions