Closed Scal-Human closed 10 months ago
Thanks for the report. This is the expected behavior as BeforeEach
and AfterEach
is considered part of the test, so properties in $____Pester.CurrentTest
isn't updated at all until all three have been executed.
Btw. $____Pester
is intentionally undocumented as it's a private API. Once a public API is provided in the future (#318) for these types of scenarios it might behave differently, ex updated per stage.
Thanks for the response. So this is suppose to work this way ? This make $____Pester just useless and no possible way (other than custom trick) to get test status information about current test in the AfterEach (which is after the test and not part of the test). Exact ? The fact that the Path to the test is correct makes us think this variable is populated. Why no just remove it ? Not working + not documented + no intention to make it work = confusing situation.
Thanks, anyway
... get test status information about current test in the AfterEach (which is after the test and not part of the test). Exact ?
Currently in Pester v5 BeforeEach
and AfterEach
is considered part of the test and are executed in a single execution. The CurrentTest
object is updated before this execution and after (e.g. determine Result).
We could compare it to an school exam:
It
-block)If you fail at any of these steps, you've failed the exam. So until all three steps are complete it's too early to determine the final Result
.
I fully agree that being able to get the current Result
during AfterEach
is a special case, as it may help you collect more data for troubleshooting. That particular scenario is tracked in #1821 which is pending #318 for a way to expose the information.
Whether a failure in AfterEach
should modify the final Result
is another discussion. @nohwnd Do you know how teardown errors behave in other test frameworks?
The fact that the Path to the test is correct makes us think this variable is populated. Why no just remove it ? Not working + not documented + no intention to make it work = confusing situation.
As mentioned it is a private API, intentionally given a weird variable name and being undocumented, to avoid users from depending on it.
While not being useful for end users, it still brings us value during troubleshooting, debugging and figuring out which parts of it that should be exposed in the final public API (#318).
Hello, Many thanks for this detailed answer.
I close the issue as it wil not be solved, and I use a different approach anyway.
Have a nice weekend.
Checklist
What is the issue?
Reviewing tests for multiple module, I wanted to have a verbose trace during Pester analysis after each test. I created a context within which an AfterEach block is defined and I am expecting the $Pester.CurrentTest to contain test information after its execution (Passed or Status, Duration), but the $Pester.CurrentTest is partialy populated (Path is ok, Executed is ok, but Passed is always false).
Disclaimer: I was unable to find the documentation about $____Pester
Expected Behavior
Ok : First test gives the Pester version and is meant to succeed KO; AfterEach should show Status , Duration, and Passed true but it is false Ok: Second test is supposed to explode as it uses an unexisting drive KO; AfterEach should show Status , Duration but are missing.
Steps To Reproduce
Note: I also tried by having having Context inside Describe with the same result.
outputs:
results are correct:
Describe your environment
I am running on Windows 10 with PowerShell core 7.3.10.
Possible Solution?
No response