Pester
Pester copied to clipboard
If Invoke-Pester is called, the previous Mock will be invalidated
If Invoke-Pester
is called, the previous mocks will be invalidated.
Of course, I know that requirements can be implemented in other ways, and this is just a report.
https://github.com/Andy-AO/Shared/tree/master/PesterMockBug
Pester version : 5.1.1 C:\Users\Andy\Documents\PowerShell\Modules\Pester\5.1.1\Pester.psm1
PowerShell version : 7.1.3
OS version : Microsoft Windows NT 10.0.18363.0
This is because on Invoke-Pester we clean up all Mocks that we can find to get rid of zombie mocks from cancelled runs. This cleanup will run as well when you run Invoke-Pester inside of your test and will remove all your mock hooks. I think it's reasonable to detect Pester in Pester and skip that cleanup automatically. If we can ensure that the thing we use to detect Pester in Pester won't survive cancelled run - that is: we can ensure that the cleanup will run for the top level Invoke-Pester even after cancellation.
@fflaten what do you think? I would write a message to diag log for this, and I think we can check the presence of $Pester variable, because that is scoped to Invoke-Pester invocation.
Run 1) Invoke-Pester -> checks for $Pester, it's not there, it cleans | ----> Invoke-Pester -> checks for $Pester, it's there, it does not clean ... cancel
Run 2) Invoke-Pester -> checks for $Pester, it's not there, it cleans
@fflaten what do you think? I would write a message to diag log for this, and I think we can check the presence of $Pester variable, because that is scoped to Invoke-Pester invocation.
Sounds good. Are there no other conflicts when running Pester in Pester? I haven't used it much since I thought it was unsupported.
Test drive, we would have to persist and re-map the folder. Right now we just delete it as soon as we enter the second Pester.
Test drive, we would have to persist and re-map the folder. Right now we just delete it as soon as we enter the second Pester.
Tracked in #2147, also for TestRegistry.