Open crlgb opened 1 month ago
This is by design. We evaluate the name just after BeforeEach, so values from BeforeAll and BeforeEach are reflected into the string. This seemed like the best place, since the Before* steps are setting up values and should hopefully have all the right data for the test.
We also need to evaluate in a scope that is on the same level as the BeforeEach.
The code here could probably be changed to capture the error from BeforeEach, run more code to evaluate the name of the test, and rethrow the error.
https://github.com/pester/Pester/blob/main/src/Pester.Runtime.ps1#L643
This is known limitation and currently by design.
The variables are expanded after setup (BeforeAll/-Each
) to have all variables/reference available. An exception during setup stops further processing to avoid unexpected results like old variables from parent scope being used etc.
@nohwnd Candidate for v6? Does anyone depend on BeforeEach/-All
variables for templates?
IDK if we technically we can fix it.
There can also be a different complaint which is: the variables from my tests / AfterAll are not expanded.
Chiming in on this topic:
I built a framework that can parse configuration files to pester tests. In it there is an option to specifiy if a test is terminating or not. As you can use Set-ItResult (or its errorrecord) within BeforeEach the tests get the correct state but their title is not set correctly.
The variables might still be present (especially when coming from the testdata) and one could atleast try to expand them.
Edit: Another case in which the above happens is when the Test is skipped via the -Skip parameter
Checklist
What is the issue?
Output does not resolve the current item
$_
in the output.Expected Behavior
Steps To Reproduce
Describe your environment
Possible Solution?
No response