Closed GSDragoon closed 6 months ago
Hi. This is intended PowerShell behavior and not exclusive to Peater. When you use [Parameter()]
or [CmdletBinding()]
it becomes an advanced function/script. Arguments are then disabled by default so if you try to splat or call with an undefined parameter it will throw.
You need to provide Data compatible with every script or use multiple calls to New-PesterContainer
with the appropriate Data values per script.
@GSDragoon does it work to use ValueFromRemainingArguments
?
Hi. This is intended PowerShell behavior and not exclusive to Peater. When you use
[Parameter()]
or[CmdletBinding()]
it becomes an advanced function/script. Arguments are then disabled by default so if you try to splat or call with an undefined parameter it will throw.You need to provide Data compatible with every script or use multiple calls to
New-PesterContainer
with the appropriate Data values per script.
Thanks for the quick response. Guess I shouldn't be too surprised this is the case. Sounds like I need to be okay with a workaround or make bigger design changes
@GSDragoon does it work to use
ValueFromRemainingArguments
?
Yes, this works. Suppose this is another workaround, to add this parameter to each file.
param (
[Parameter()]
[string] $Parameter1,
[Parameter(ValueFromRemainingArguments)]
[object[]]$RemainingParametersPlaceholder
)
Checklist
What is the issue?
I have a suite of tests across multiple files that are the target of a single Pester Container definition that is used to pass parameters into the tests. The path of the container uses a wildcard to target all the test files. Not all of the test files use the same parameters. The parameters also make use of the Parameter attribute (such as forcing it to be mandatory). Manually building a test container for each combination isn't really feasible.
When I run the tests, the discovery fails for the files that do not have all the parameters (and make use of the Parameter attribute).
Expected Behavior
I would expect the tests files that do not have all the parameters to work. They should ignore the extra parameters like how it works if the Parameter attribute is not applied to the parameter.
Steps To Reproduce
Commands to build the Pester Container, Configuration and run the tests.
Working test files.
Test files that do not work.
Describe your environment
Pester version : 5.5.0 C:\Program Files\WindowsPowerShell\Modules\Pester\5.5.0\Pester.psm1 PowerShell version : 5.1.19041.3031 OS version : Microsoft Windows NT 10.0.19045.0
Possible Solution?
There are two options I see for workarounds, neither are that great, but not terrible.