-
-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'-ErrorAction Stop' not respected by 'Invoke-Pester' #1843
Comments
Two things here. You are setting .exit = $true, which will exit on failure. If you are trying this in VSCode then seemingly nothing happens, because exit is ignored there. So you won't reach "catch" and you won't reach code after catch. If you remove .exit it will still not work though. Your $invokePesterResult will be $null. The way that errors are reported in Discovery is still quite broken. It should either return an object with results or properly fail, but not none of those things. |
I made it much better in the linked PR, it now reports this for your example:
You still have to throw the exception yourself though. |
Thank you Jakub for fixing this. So if I understand it correctly the property |
Yes pretty much. FailedContainers has the whole Container object in it (a container represents a file / scriptblock). This is meant to give you feedback when there is code that prevents the whole container from running (in the Run phase), e.g. code outside of a test that throws, or a bug in pester code. I am re-using that here for discovery as well because it makes sense, I just did not do it that way originally for some reason. It will continue to next file and it will continue to test run, but the whole run will be marked as failed (see Result in the object above). I will be adding an option to throw on failed tests (instead of exiting). (Note to self: Not sure if I can exit in finally after throwing an exception, when both exit and throw is enabled, but if I can't I should prefer throwing over exit I think, because exit does not work correctly in VSCode, but throwing exception should fail both CI run as well as VSCode run). |
One small tip I would like to suggest with regards to naming properties and what they stand for. It might be a good idea to use the name @{
Success: $true # or $false or NULL if skipped
Skipped: $true # or $false
} I see there's already an @{
Success: $true # or $false or NULL if skipped
ExecutedAt: 08/04/2021 00:04:31
} Just an idea, I might not understand all the implications involved. It would just be a lot simple to have less duplication in property fields and names. Smaller objects are also more easy to understand and to work with. I'm already happy that Pester will not break anymore on a broken test in a single file :) |
I tried to avoid all the dependencies in between fields because then changing one (because of fixing a bug) will change behavior in many other places. For that reason I am trying to keep the data as raw as possible. I can also use that to debug when I get a repro and something is wrong. Passed means that the test passed, but it will be false when the test is skipped or not run for example. This does not mean the test failed though. If you want to know what exactly happened look at the Result field. That one indicates the actual result. |
General summary of the issue
The code
Invoke-Pester -ErrorAction Stop
placed in aTry
clause does not trigger theCatch
clause.Describe your environment
Steps to reproduce
The code below clearly is a failing test that was working with Pester 4 but no longer works with Pester 5. For that reason we would expect
Invoke-Pester -ErrorAction Stop
to trigger theCatch
clause. But whatever we try we can't get it to do so.Expected Behavior
Throw the error message "Failed to execute the Pester tests: The 'In' command was found in the module 'Pester'..."
Current Behavior
Catch
clause not reached, so error handling is very difficult. Although a big red error is visible in the console.Possible Solution? (optional)
Respect the
-ErrorAction
request.As a workaround to start with Pester 5 reporting we tried to exclude all paths that still contained old Pester 4 tests that would break 'Invoke-Pester'. But when we do that we see that Pester still fails and reports back the same error. When we use
ExcludePath
we would expect Pester to not look at these broken test files at all.Error:
The text was updated successfully, but these errors were encountered: