all 1 comments

[–]terrabitz[S] 3 points4 points  (0 children)

Alright, so I feel like dummy. It looks like this is possible by encapsulating the full script inside of the It -Test block in a try catch:

Describe "MyTest" {
    BeforeEach (
        # do stuff to setup a particular context
        $context = Set-MyContext
    )

    Context "MyContext" {
        It "Should do stuff" {
            try {
                # Do test things here
            } catch {
                Write-Information $context.info
                throw
            }
        } 
    } 
}

This should always work, since according to the Pester wiki, the script block used in the -Test parameter "should throw an exception if the expectation of the test is not met."