Have Pester not collect Non-Terminating errors

Welcome Forums Pester Have Pester not collect Non-Terminating errors

Viewing 1 reply thread
  • Author
    Posts
    • #273556
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      Hi All, I’m running into this issue where I’m casting a variable to [int] type, but unfortunately for me the data being fed is not always in a correct format to succeed 100%. I’ve created a basic test to illustrate my issue:

      When I run this test it always Fails and never processes any of the Assertions:

      [-] Test Non-Terminating Error.Non-Terminating Error.Non-Terminating Error 21ms (20ms|1ms) FormatException: Input string was not in a correct format. PSInvalidCastException: Cannot convert value “oc” to type “System.Int32”. Error: “Input string was not in a correct format.” ArgumentTransformationMetadataException: Cannot convert value “oc” to type “System.Int32”. Error: “Input string was not in a correct format.” at , .\assets\_Test.Tests.ps1:11 Tests completed in 1.47s Tests Passed: 0, Failed: 1, Skipped: 0 NotRun: 0

      I’ve already tried:

      • Configuring Pester Should ErrorPreference to ‘Continue’
      • Setting PowerShell Error Action Preference to ‘SilentlyContinue’  ( $ErrorActionPreference = 'SilentlyContinue')
      • Try/Catch doesn’t catch because its Non-Terminating

      Is there a way to have pester ignore any non-terminating error that happens within the IT block and just execute the Assertions?

      I’m running Pester 5.0.3 on PowerShell 5.1

      Please Help!

    • #273981
      Senior Moderator
      Topics: 9
      Replies: 1447
      Points: 5,419
      Helping Hand
      Rank: Community MVP

      Here the error will occur during the type conversion at [int]$Number = 'oc' . So you having a test for this line is better.
      Its best to use [int]::TryParse() method which will not throw any error.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.