Skip to content

Passing variables from Discovery to Run phases #2568

Answered by fflaten
dommyzee asked this question in Q&A
Discussion options

You must be logged in to vote

Yes. Using a wrapper dictionary through -ForEach is the recommended approach. Tips:

  • You don't need the array wrapper and can provide the dictionary directly like Describe 'Check Lookups' -ForEach @{ DiscoveryLookups = $discoveryLookups }
  • Dictionary keys are automatically made variables so you can avoid the BeforeAll reassigning $_.Data and just use $DiscoveryLookups in Run-phase. Using capital key/variable letter to illustrate.

The alternative is script parameters (params($MyParam = 'default data')). They're automatically included in Run as well by Pester as container (file) level Data. It's typically used for providing external data when invoking Pester - but it works with default valu…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dommyzee
Comment options

Answer selected by dommyzee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants