1

I have a powershell script, which in parallel, invokes instances of Pester, with:

Invoke-Pester @{Path= "somepath/file.tests.ps1";
Parameters = @{...
...}} -Tag 'value' -OutputFile $xmlpath -OutputFormat NUnitXML -EnableExit

There is often a run, whereby at least one of the instances to invoke pester, fails at the outside, throwing a DriveNotFoundException:

Executing script somepath/file.tests.ps1

  Describing Testcase
    [-] Error occurred in Describe block
 0ms
      DriveNotFoundException: Cannot find drive. A drive with the name 'TestRegistry' does not exist.
      at Get-TestRegistryPath, C:\Users\VssAdministrator\Documents\PowerShell\Modules\Pester\4.6.0\Functions\TestRegistry.ps1: line 60

I have been unable to catch this error, with either:

try {Invoke-Pester @{Path= "somepath/file.tests.ps1";
    Parameters = @{...
    ...}} -Tag 'value' -OutputFile $xmlpath -OutputFormat NUnitXML -EnableExit} catch {...}

or

try {
    Describe "Testcase" -Tag 'value' {...}
} catch { ... }

How can I catch this error?

  • 1
    Try adding `-ErrorAction Stop` to your call of `Invoke-Pester`. Try..Catch doesn't trigger unless the exception is terminating. Using -ErrorAction Stop changes non-terminating errors to terminating. – Mark Wragg Mar 17 '22 at 14:42
  • Thanks @MarkWragg giving that a try! –  Mar 17 '22 at 17:50

0 Answers0