Skip to content

BeforeAll errors in ScriptBlocks lack error message (container name) #2636

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

Closed
3 tasks done
davidmatson opened this issue Apr 8, 2025 · 2 comments
Closed
3 tasks done

Comments

@davidmatson
Copy link
Contributor

Checklist

What is the issue?

When a ScriptBlock fails in BeforeAll, there is no container name text on the line that has the failure (after "[-]").

Expected Behavior

The [-] line contains the container name (just like it is displayed currently in the BeforeAll failures summary at the end).

Steps To Reproduce

$container = New-PesterContainer -ScriptBlock {
    BeforeAll {
        throw 'very bad'
    }

    Describe 'Container Failure Tests' {
        It 'would pass' {
        }

        It 'also would pass' {
        }
    }
}
$configurationHashtable = @{
    Run=@{ Container=$container };
    Output=@{ Verbosity='Detailed' };
    Debug=@{ ShowNavigationMarkers=$true; ShowStartMarkers=$true }
}
$configuration = New-PesterConfiguration -Hashtable $configurationHashtable
Invoke-Pester -Configuration $configuration

Describe your environment

No response

Possible Solution?

No response

@davidmatson
Copy link
Contributor Author

davidmatson commented Apr 8, 2025

Actual output today:

Pester v6.0.0-alpha5

Starting discovery in 1 files.
Discovery found 2 tests in 774ms.
Running tests.
[-]
    BeforeAll {
        throw 'very bad'
    }

    Describe 'Container Failure Tests' {
        It 'would pass' {
        }

        It 'also would pass' {
        }
    }
 failed with:
RuntimeException: very bad
at <ScriptBlock>, C:\some_path\Tests.ps1:3
Tests completed in 2.41s
Tests Passed: 0, Failed: 2, Skipped: 0, Inconclusive: 0, NotRun: 0
Container failed: 1
  - <ScriptBlock>:C:\some_path\Tests.ps1:1
  - 

Expected output snippet:

Running tests.
[-] <ScriptBlock>:C:\some_path\Tests.ps1:1 failed with:
RuntimeException: very bad

@davidmatson
Copy link
Contributor Author

i.e., it should work in the same way as it does for a container that's a file, except it uses :path:line for the name

Output of the equivalent case using a file rather than a ScriptBlock:

Pester v6.0.0-alpha5

Starting discovery in 1 files.
Discovery found 2 tests in 119ms.
Running tests.

Running tests from 'OtherFile.Tests.ps1'
[-] OtherFile.Tests.ps1 failed with:
RuntimeException: very bad
at <ScriptBlock>, C:\some_path\OtherFile.Tests.ps1:2
Tests completed in 201ms
Tests Passed: 0, Failed: 2, Skipped: 0, Inconclusive: 0, NotRun: 0
Container failed: 1
  - C:\some_path\OtherFile.Tests.ps1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant