Skip to content

Return variables from Tests #2395

Discussion options

You must be logged in to vote

Hi. One approach would be to use the StandardOutput-property on test/block-objects found in $PesterResults. It contains any output from the scriptblock.

For a failed test you'd have to output before the failure occurs, or grab it from a parent element.
It really depends on where you grab the values. Ex.

# My.Tests.ps1
Describe 'd' {
    BeforeAll {
        [pscustomObject]@{
            Stage = 'BeforeAll'
        }
    }
    It 'Success local' {
        [pscustomObject]@{
            Stage = 'Success test'
        }
    }

    It 'Failed local' {
        [pscustomObject]@{
            Stage = 'Failed test'
        }
        1 | Should -Be 2
    }

    It 'Failed parent' {
        1 | Sho…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by SQLDBAWithoutABeard
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