The root cause is that
Initialize-TestEnvironment saves the current machine environment variable PSModulePath and then updates it with the path to the built module.
|
$oldPSModulePath = $env:PSModulePath |
|
|
|
if ($null -ne $oldPSModulePath) |
|
{ |
|
$oldPSModulePathSplit = $oldPSModulePath.Split([io.path]::PathSeparator) |
|
} |
|
else |
|
{ |
|
$oldPSModulePathSplit = $null |
|
} |
|
|
|
if ($oldPSModulePathSplit -ccontains $moduleParentFilePath) |
|
{ |
|
# Remove the existing module path from the new PSModulePath |
|
$newPSModulePathSplit = $oldPSModulePathSplit | Where-Object { $_ -ne $moduleParentFilePath } |
|
} |
|
else |
|
{ |
|
$newPSModulePath = $oldPSModulePath |
|
} |
|
|
|
$RequiredModulesPath = Join-Path -Path $moduleParentFilePath 'RequiredModules' |
|
if ($newPSModulePathSplit -cnotcontains $RequiredModulesPath) |
|
{ |
|
$newPSModulePathSplit = @($RequiredModulesPath) + $newPSModulePathSplit |
|
} |
|
|
|
$newPSModulePathSplit = @($moduleParentFilePath) + $newPSModulePathSplit |
|
$newPSModulePath = $newPSModulePathSplit -join [io.Path]::PathSeparator |
|
|
|
Set-PSModulePath -Path $newPSModulePath |
- The tests run for SqlSetup and the installation sets a new path to SQLPS in machine environment variable
PSModulePath.
https://github.com/dsccommunity/SqlServerDsc/blob/f9bde8a61230754c078257d115103726f749570a/tests/Integration/DSC_SqlSetup.Integration.Tests.ps1#L171-L175
|
if ($TestEnvironment.OldPSModulePath -ne $env:PSModulePath) |
|
{ |
|
Set-PSModulePath -Path $TestEnvironment.OldPSModulePath |
|
|
|
if ($TestEnvironment.TestType -in ('Integration','All')) |
|
{ |
|
# Restore the machine PSModulePath for integration tests. |
|
Set-PSModulePath -Path $TestEnvironment.OldPSModulePath -Machine |
|
} |
|
} |
- After the tests finishes the command
Restore-TestEnvironment reverts the machine environment variable PSModulePath to the one saved in step 1 overwriting the new path that was set in step 2.
- All other tests no longer finds the module SQLPS and fails.
Originally posted by @johlju in dsccommunity/SqlServerDsc#1932 (comment)
The root cause is that
Initialize-TestEnvironmentsaves the current machine environment variablePSModulePathand then updates it with the path to the built module.DscResource.Test/source/Public/Initialize-TestEnvironment.ps1
Lines 177 to 207 in 73d6c32
PSModulePath.https://github.com/dsccommunity/SqlServerDsc/blob/f9bde8a61230754c078257d115103726f749570a/tests/Integration/DSC_SqlSetup.Integration.Tests.ps1#L171-L175
DscResource.Test/source/Public/Restore-TestEnvironment.ps1
Lines 38 to 47 in 73d6c32
Restore-TestEnvironmentreverts the machine environment variablePSModulePathto the one saved in step 1 overwriting the new path that was set in step 2.Originally posted by @johlju in dsccommunity/SqlServerDsc#1932 (comment)