-
-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default parameter values are not applied in the test script #1980
Comments
Parameters in the script are treated the same as variables defined in [CmdletBinding()]
param (
[Parameter()]
[string]
[ValidateSet('DEV', 'PROD')]
$Environment = 'DEV'
)
# Using the same key-name as original parameter name just to make it clean.
# -ForEach @{ MyVar = $Environment } would require you to use $MyVar | Should -BeExactly 'DEV' in the test
Describe "My tests" -ForEach @{ Environment = $Environment } {
It "Environment parameter should be accessible" {
$Environment | Should -BeExactly 'DEV'
}
}
The reason |
Yeah, valid. @fflaten Even with the workaround you provided. I think we should look into detecting the default values from the parameter set and assigning them as default Data to the root, because then you can use them in the top-level BeforeAll. And it also works nicely if you have more than 1 parameter with default value. |
I agree. The comment was meant as a workaround and explanation for now while I figured out if something better is even possible. Think I might have an idea in upcoming draft PR, though I don't think I'm able to detect default values set to |
General summary of the issue
I'm working on a new test script and I need it to have a parameter defining the environment to be tested (Dev/Prod). I configured it to use Dev as a default, however it seems that those defaults are just ignored.
Describe your environment
Steps to reproduce
Test script:
Running it either with
Invoke-Pester -Path
or with VSCode'sDebug tests
intellisense link resolves with a failed test:-->
It only works if I initialize a PesterContainer with the Data provided
Expected Behavior
I wish it would pick up the default value for the environment, cause that would make it so much easier to debug it through VSCode
Current Behavior
Defaults for script parameters are completely ignored
Possible Solution? (optional)
I can workaround the script to use environmental variables to drive the tests, but this approach seems more intuitive.
The text was updated successfully, but these errors were encountered: