Repository navigation
Skip DSC tests if pwsh is not available - #2039
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
🟡 Changes recommended
DSC tests may still run without required setup, and skip defaults may leak into later tests.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Updates DSC tests to skip when pwsh is unavailable.
Changes:
- Adds
pwshavailability checks across DSC test groups. - Configures and restores Pester skip defaults.
- Fixes test comment punctuation.
File summaries
| File | Summary |
|---|---|
test/DscResource/PSResourceGetDSCResource.Tests.ps1 |
Adds conditional skipping and cleanup for DSC tests. |
Review details
Suppressed comments (9)
test/DscResource/PSResourceGetDSCResource.Tests.ps1:220
- This cleanup has the same scope problem: the skip default was added by mutating the shared
$PSDefaultParameterValueshashtable, while the unscoped assignment does not restore the global variable. A laterDescribecan inheritit:skipand silently skip its tests; restore$global:PSDefaultParameterValueshere.
$PSDefaultParameterValues = $originalDefaultParameterValues
test/DscResource/PSResourceGetDSCResource.Tests.ps1:580
- The skip path mutates the shared
$PSDefaultParameterValueshashtable, but this unscoped assignment only rebinds the current Pester scope and may leaveit:skipenabled for subsequent CI tests in the same run. Restore the global variable, consistent with the existing cleanup at lines 457-458.
$PSDefaultParameterValues = $originalDefaultParameterValues
test/DscResource/PSResourceGetDSCResource.Tests.ps1:56
- Pester 4 registers the
Itblocks before executingBeforeAll, so$skipTestis not available when this-Skipvalue is bound; theIt:Skipdefault set below is likewise too late. Whenpwshis absent, setup returns but the tests still execute with$script:dscExeunset. Compute the flag before eachDescribeand apply it during test registration, or use an in-test skip result.
$skipTest = $null -eq (Get-Command -Type Application -Name pwsh -ErrorAction SilentlyContinue)
test/DscResource/PSResourceGetDSCResource.Tests.ps1:109
- This
It:Skipdefault is assigned fromBeforeAll, after Pester 4 has registered the tests in thisDescribe, so it does not skip them whenpwshis absent. The setup returns, but the repository tests still run without DSC initialization. Move the check beforeDescribeand pass-Skipat registration time (or set the result to skipped inside each test).
$PSDefaultParameterValues['it:skip'] = $skipTest
test/DscResource/PSResourceGetDSCResource.Tests.ps1:211
- This
It:Skipdefault is assigned fromBeforeAll, after Pester 4 has registered the tests in thisDescribe, so it does not skip them whenpwshis absent. The setup returns, but the PSResourceList tests still run without DSC/repository initialization. Move the check beforeDescribeand pass-Skipat registration time (or set the result to skipped inside each test).
$PSDefaultParameterValues['it:skip'] = $skipTest
test/DscResource/PSResourceGetDSCResource.Tests.ps1:381
- This
It:Skipdefault is assigned fromBeforeAll, after Pester 4 has registered the tests in thisDescribe, so it does not skip them whenpwshis absent. The setup returns, but these E2E tests still execute without the DSC setup. Move the check beforeDescribeand pass-Skipat registration time (or set the result to skipped inside each test).
$PSDefaultParameterValues['it:skip'] = $skipTest
test/DscResource/PSResourceGetDSCResource.Tests.ps1:442
- This
It:Skipdefault is assigned fromBeforeAll, after Pester 4 has registered the tests in thisDescribe, so it does not skip them whenpwshis absent. The setup returns, but the PSResourceList E2E tests still execute without DSC initialization. Move the check beforeDescribeand pass-Skipat registration time (or set the result to skipped inside each test).
$PSDefaultParameterValues['it:skip'] = $skipTest
test/DscResource/PSResourceGetDSCResource.Tests.ps1:566
- This
It:Skipdefault is assigned fromBeforeAll, after Pester 4 has registered the tests in thisDescribe, so it does not skip them whenpwshis absent. The setup returns, but the error-code tests still execute without DSC initialization. Move the check beforeDescribeand pass-Skipat registration time (or set the result to skipped inside each test).
$PSDefaultParameterValues['it:skip'] = $skipTest
test/DscResource/PSResourceGetDSCResource.Tests.ps1:390
$PSDefaultParameterValuesis inherited from the global scope, and the assignment here creates/replaces a local variable in the Pester block; it does not restore the global hashtable that was modified inBeforeAll. As a result,It:Skip = $truecan leak into later describes or test files. Restore the global variable, as the neighboring setup does.
$PSDefaultParameterValues = $originalDefaultParameterValues
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
PR Summary
This pull request updates the test suite in
PSResourceGetDSCResource.Tests.ps1to improve compatibility and reliability when PowerShell 7 (pwsh) is not available. The main enhancement is the conditional skipping of tests ifpwshis not present, ensuring that tests only run in supported environments and do not fail unnecessarily.Test Environment Compatibility Improvements:
pwshusingGet-Command, and set a$skipTestvariable accordingly. Ifpwshis missing, tests are skipped gracefully. [1] [2] [3] [4] [5] [6]$PSDefaultParameterValuesdictionary is cloned and modified to skip tests, and then restored inAfterAllblocks to avoid side effects on other tests. [1] [2] [3] [4] [5] [6]Test Suite Robustness:
AfterAllblock to restore the original test state if tests are skipped, ensuring that subsequent tests are not affected by the skip logic. [1] [2] [3] [4] [5]-Skipparameter is dynamically set on individualItblocks based on the presence ofpwsh, making the test skipping explicit and traceable. [1] [2] [3] [4] [5] [6]These changes collectively make the test suite more robust and environment-aware, preventing false negatives in CI and local runs where PowerShell 7 is not installed.
PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.