Closed tbergstedt closed 3 years ago
Could it be that you invoked this file without specifying the Directory-parameter (relying on default-value)? If so, can you try again like:
$container = New-PesterContainer -Path 'My.Tests.ps1' -Data @{ Directory = "A\Valid\Path" }
Invoke-Pester -Container $container -Output Detailed
I haven't been able to test it myself yet, but my immediate thought is that this is similar to #1812 and #1730, in which case we need to provide a default value for the $Data
-parameter here since it's always passed to the scriptblock (content of "My.Tests.ps1").
https://github.com/pester/Pester/blob/5234884fff3202fb4c1b9f04bfd8c7e227095e87/src/Pester.Runtime.psm1#L2378-L2387
Thanks, that worked! I was actually struggling with the problem that the $Directory
parameter was getting set to $null
at certain conditions in Pester v5, but failed to see how. Setting it at runtime, like
PS\> .\My-PesterScript.ps1 -Directory C:\path\to\valid\directory
doesn't work: I get the exception System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'Directory' because it is null.
when entering the Describe
block.
But it worked using your suggested syntax. I don't think it is as straightforward as before, but then again I'm not using Pester in the most standard way.
Similar to the related PRs in my last post, this is hopefully a simple fix. Will look into it later. As for specifying the parameters directly to the script, that is pending #1787
General summary of the issue
When using
ParameterSetName
attribute on parameters in Pester scripts, the execution fails with an exception.Describe your environment
Pester version : 5.1.1 C:\Users\tober\Documents\PowerShell\Modules\pester\5.1.1\Pester.psm1 PowerShell version : 7.1.2 OS version : Microsoft Windows NT 10.0.18363.0
Steps to reproduce
My setup looks like this:
-->
Expected Behavior
Standard test execution, all items in
$changedItems
should be evaluated on their encoding.Current Behavior
Execution crashes when entering
Describe
block with exception:When removing
ParameterSetName
attribute from the parameter, the execution succeeds.