AzureDevOpsExtension icon indicating copy to clipboard operation
AzureDevOpsExtension copied to clipboard

CommandNotFoundException only in AzureDevops

Open FelixBrunet opened this issue 5 years ago • 2 comments

Where are you running it?

  • Azure DevOps Service (VSTS)

Expected behaviour and actual behaviour

CommandNotFoundException: Could not find Command PSIISReset

I import with in Tests.ps1 . "$PSScriptRoot..\ArielDbCore\IISOperations.ps1"

	Mock -CommandName PSIISReset -MockWith { 
			Write-Output "Called fake PSIISReset"
		}

My pipeline :

  • task: Pester@10 inputs: scriptFolder: "$(System.DefaultWorkingDirectory)\ArielDb-Orchestrator\Tests.ps1" resultsFile: "$(System.DefaultWorkingDirectory)\Test-Pester-ArielDb-Orchestrator.XML" CodeCoverageOutputFile: "$(System.DefaultWorkingDirectory)\ArielDb-OrchestratorCoverage.XML" usePSCore: False CodeCoverageFolder: "$(System.DefaultWorkingDirectory)\ArielDb-Orchestrator" preferredPesterVersion: '5.0.4' additionalModulePath: '$(System.DefaultWorkingDirectory)\ArielDb-Orchestrator'

Steps to reproduce the problem

It run fine on my machine using pester 5.0.4 but not with AzureDevops I try setting 32bit=true, switching from importmodule to dotsourcing, preferredPesterVersion , additionalModulePath (which is not the good one right now, I dont have only one path for all import)

I think it's because i used powershell v5.1 on my machine, and remote is 7.1 ?

FelixBrunet avatar Jan 08 '21 17:01 FelixBrunet

Azure DevOps will default to Windows PowerShell (5.1) and ony use PowerShell (7.x) when you specify the usePSCore option to true.

Can you share some more of your tests file? Where are you declaring the mock? Where are you doing the import/dotsourcing?

ChrisLGardner avatar Jan 09 '21 11:01 ChrisLGardner

I found it today This was working with debugger but not with Invoke-Pester , i fix it placing import in BeforeAll. When you have no beforeall , it run fine using Tests.ps1 but not with Invoke-Pester

FelixBrunet avatar Jan 13 '21 20:01 FelixBrunet