Skip to content

Skip DSC tests if pwsh is not available - #2039

Merged
alerickson merged 3 commits into
masterfrom
SkipDSCOnWindowsPS
Sep 15, 2026
Merged

alerickson merged 3 commits into
masterfrom
SkipDSCOnWindowsPS

Conversation

@adityapatwardhan

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

PR Summary

This pull request updates the test suite in PSResourceGetDSCResource.Tests.ps1 to improve compatibility and reliability when PowerShell 7 (pwsh) is not available. The main enhancement is the conditional skipping of tests if pwsh is not present, ensuring that tests only run in supported environments and do not fail unnecessarily.

Test Environment Compatibility Improvements:

  • All major test blocks now check for the presence of pwsh using Get-Command, and set a $skipTest variable accordingly. If pwsh is missing, tests are skipped gracefully. [1] [2] [3] [4] [5] [6]
  • The $PSDefaultParameterValues dictionary is cloned and modified to skip tests, and then restored in AfterAll blocks to avoid side effects on other tests. [1] [2] [3] [4] [5] [6]

Test Suite Robustness:

  • Each test group includes an AfterAll block 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]
  • The -Skip parameter is dynamically set on individual It blocks based on the presence of pwsh, 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

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@adityapatwardhan

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 pwsh availability 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 $PSDefaultParameterValues hashtable, while the unscoped assignment does not restore the global variable. A later Describe can inherit it:skip and silently skip its tests; restore $global:PSDefaultParameterValues here.
            $PSDefaultParameterValues = $originalDefaultParameterValues

test/DscResource/PSResourceGetDSCResource.Tests.ps1:580

  • The skip path mutates the shared $PSDefaultParameterValues hashtable, but this unscoped assignment only rebinds the current Pester scope and may leave it:skip enabled 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 It blocks before executing BeforeAll, so $skipTest is not available when this -Skip value is bound; the It:Skip default set below is likewise too late. When pwsh is absent, setup returns but the tests still execute with $script:dscExe unset. Compute the flag before each Describe and 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:Skip default is assigned from BeforeAll, after Pester 4 has registered the tests in this Describe, so it does not skip them when pwsh is absent. The setup returns, but the repository tests still run without DSC initialization. Move the check before Describe and pass -Skip at registration time (or set the result to skipped inside each test).
            $PSDefaultParameterValues['it:skip'] = $skipTest

test/DscResource/PSResourceGetDSCResource.Tests.ps1:211

  • This It:Skip default is assigned from BeforeAll, after Pester 4 has registered the tests in this Describe, so it does not skip them when pwsh is absent. The setup returns, but the PSResourceList tests still run without DSC/repository initialization. Move the check before Describe and pass -Skip at registration time (or set the result to skipped inside each test).
            $PSDefaultParameterValues['it:skip'] = $skipTest

test/DscResource/PSResourceGetDSCResource.Tests.ps1:381

  • This It:Skip default is assigned from BeforeAll, after Pester 4 has registered the tests in this Describe, so it does not skip them when pwsh is absent. The setup returns, but these E2E tests still execute without the DSC setup. Move the check before Describe and pass -Skip at registration time (or set the result to skipped inside each test).
            $PSDefaultParameterValues['it:skip'] = $skipTest

test/DscResource/PSResourceGetDSCResource.Tests.ps1:442

  • This It:Skip default is assigned from BeforeAll, after Pester 4 has registered the tests in this Describe, so it does not skip them when pwsh is absent. The setup returns, but the PSResourceList E2E tests still execute without DSC initialization. Move the check before Describe and pass -Skip at registration time (or set the result to skipped inside each test).
            $PSDefaultParameterValues['it:skip'] = $skipTest

test/DscResource/PSResourceGetDSCResource.Tests.ps1:566

  • This It:Skip default is assigned from BeforeAll, after Pester 4 has registered the tests in this Describe, so it does not skip them when pwsh is absent. The setup returns, but the error-code tests still execute without DSC initialization. Move the check before Describe and pass -Skip at registration time (or set the result to skipped inside each test).
            $PSDefaultParameterValues['it:skip'] = $skipTest

test/DscResource/PSResourceGetDSCResource.Tests.ps1:390

  • $PSDefaultParameterValues is 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 in BeforeAll. As a result, It:Skip = $true can 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.

Comment thread test/DscResource/PSResourceGetDSCResource.Tests.ps1 Outdated
Comment thread test/DscResource/PSResourceGetDSCResource.Tests.ps1 Outdated
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>
@adityapatwardhan

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@alerickson
alerickson self-requested a review September 15, 2026 00:03
@alerickson
alerickson merged commit 5d09008 into master Sep 15, 2026
12 checks passed
@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) deleted the SkipDSCOnWindowsPS branch September 15, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants