Using Pester tags in test logic

Welcome Forums Pester Using Pester tags in test logic

  • This topic has 1 reply, 2 voices, and was last updated 1 year ago by
Viewing 1 reply thread
  • Author
    • #160851
      Topics: 7
      Replies: 9
      Points: 52
      Rank: Member

      Is it possible to use Pester tags in logic?  For example, I have the following Describe block:

      Describe "Connected to vCenter instance 1" -Tag @("vmware-vdi","vmware-all") {
        Connect-ViServer MyVcenter1
        foreach ($ConnectedViServerin$arrConnectedViServers) {
          if ($ConnectedViServer.Name -eq$VdiVcenter) {
        It "We should be connected to the vCenter instance 1" {
          $bolConnected|Should Be $true

      Since I have two separate instances of VMware vCenter, I have to have two separate Describe blocks (using different tag arrays).  What I would like to be able to do is use a Switch statement based on the tags.  That would allow me to connect to either one or both vCenter instances in one Describe block.

    • #161949
      Topics: 0
      Replies: 28
      Points: -7
      Rank: Member

      Not possible in v4, might be possible in v5 in the future once the metadata are available to the test itself. Then you might be able to so something like `switch ($test.root.tags[0])` but that is far in the future. Theoretially you can reach into the Pester internal state and find the tag (not sure right now where it is stored) and do the same thing, but that would depend on the internal state a lot, and would not be supported or reliable.

Viewing 1 reply thread
  • The topic ‘Using Pester tags in test logic’ is closed to new replies.