Skip to content

Fall back to no dynamic parameters when a mocked command can't produce them#2755

Merged
nohwnd merged 1 commit into
mainfrom
fix/619-dynamicparam-retrieval
Jun 27, 2026
Merged

Fall back to no dynamic parameters when a mocked command can't produce them#2755
nohwnd merged 1 commit into
mainfrom
fix/619-dynamicparam-retrieval

Conversation

@nohwnd

@nohwnd nohwnd commented Jun 26, 2026

Copy link
Copy Markdown
Member

Fix #619

Mocking a command whose dynamic parameters can't be resolved while it's mocked failed the whole mock with "Cannot retrieve the dynamic parameters for the cmdlet. ...". The reported case is Set-PSRepository: its -Location parameter is built (and validated) from the package provider, and that validation throws when Pester re-runs the dynamicparam block to copy the parameter metadata onto the mock.

Pester only needs that metadata to forward the call, so when retrieving it fails - either from a cmdlet's IDynamicParameters or a function's dynamicparam block - fall back to no dynamic parameters instead of failing the mock. The mock then works as long as the call doesn't use one of those parameters (the issue's repro doesn't use -Location).

…n't produce them

Mocking a command whose dynamic parameters can't be resolved while it is mocked failed
the whole mock with `Cannot retrieve the dynamic parameters for the cmdlet`. Set-PSRepository
is the reported case: its -Location parameter is built and validated from the package
provider, which throws when Pester re-runs the dynamicparam block to copy the parameter
metadata onto the mock.

Pester only needs that metadata to forward the call, so when retrieving it fails - from a
cmdlet's IDynamicParameters or a function's dynamicparam block - fall back to no dynamic
parameters instead of failing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd marked this pull request as ready for review June 27, 2026 11:45
@nohwnd nohwnd merged commit 2fc0c06 into main Jun 27, 2026
13 checks passed
@nohwnd nohwnd deleted the fix/619-dynamicparam-retrieval branch June 27, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mock Set-PSRepository throws ParameterBindingValidationException on not existing parameter 'Location'

1 participant