调用 pester 时如何捕获 DriveNotFoundException 错误?

发布于 2025-01-15 02:22:15 字数 987 浏览 3 评论 0原文

我有一个 powershell 脚本,它并行调用 Pester 的实例,其中:

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

经常有一次运行,其中至少一个调用 pester 的实例在外部失败,抛出 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

我一直无法捕获此问题错误,可以是:

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

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

如何捕获此错误?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文