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
Reattach TestDrive and TestRegistry after running inner Invoke-Pester #2341
Conversation
} | ||
else { | ||
# this will inherit to child scopes and affect behavior of ex. TestDrive/TestRegistry | ||
$runningPesterInPester = $true |
Check warning
Code scanning / PSScriptAnalyzer
The variable 'runningPesterInPester' is assigned but never used. Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments for questions. Likely merge conflict in #2337.
@@ -638,6 +638,11 @@ function Invoke-Pester { | |||
# this will inherit to child scopes and allow Describe / Context to run directly from a file or command line | |||
$invokedViaInvokePester = $true | |||
|
|||
if ($null -ne $state) { | |||
# this will inherit to child scopes and affect behavior of ex. TestDrive/TestRegistry | |||
$runningPesterInPester = $true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we track this (and $invokedViaInvokePester
) in $state
-prop instead of inheriting the variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, why not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saving for future PR :)
#publish the global TestDrive variable used in few places within the module | ||
if (-not (& $SafeCommands['Test-Path'] "Variable:Global:$DriveName")) { | ||
& $SafeCommands['New-Variable'] -Name $DriveName -Scope Global -Value $directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this intentional to not steal a user variable?
If so, I can revert/change to only override a Pester-created value based on value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember the history, maybe it was originally not mapping TestDrive to a random directory, and inner Pester simply did not map it's own TestDrive, but instead inherited it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's been there since v2, probably to avoid nested Describe-blocks (which I assume was supported) to overwrite the TestDrive. Similar check for existing PSDrive. Should be safe to remove now.
} | ||
|
||
function New-TestDrive ([Switch]$PassThru, [string] $Path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PSScriptAnalyzer doesn't track parameters properly without a param-block it seems, so changed a few functions. Ex. this has a unused $PassThru
switch. Removed since this is internal.
Marking as ready for review, but might get a merge conflict as mentioned above. |
Reviewed and approved. Please fix the conflict :) |
137d9b7
to
bb19bbc
Compare
PR Summary
When running Pester inside Pester, it would delete the existing/parent TestDrive/TestRegistry.
This PR detects, stores and reattaches the previous TestDrive/TestRegistry drives before returning to the parent instance.
Also remaps TestDrive/TestRegistry at end of block if missing. This can occur if user code removes it or a inner/nester Invoke-Pester failed and never got to reattach it.
Fix #2147
PR Checklist
Create Pull Request
to mark it as a draft. PR can be markedReady for review
when it's ready.