Repository navigation
Description
Desired functionality: perform "run keyword and continue on failure" and support continuable failures in python code
I have many instances where I want to report multiple failures in python code, (and want the code to flow naturally). I have created all sorts of custom implementations to get close to the desired behavior.
Continue Example
Validate All Things On Page
Log end(psuedo code moment)
Introduce a function that will log a failure to the log, but will also affect the status of the test:
def validate_all_things_on_page():
continuable_validate("expected a", get_a())
continuable_validate("expected b", get_b())
continuable_validate("expected c", get_c())
print("Done!")
def continuable_validate(expected, actual):
if expected != actual:
robot.api.fail("Unfortunately a '!=' moment was detected in your code 😳", continue=True)An alternate(or additional) solution would be to introduce a context manager that controls the state of failures being reported:
def validate_all_things_on_page():
with robot.api.continue_on_failures():
validate("expected a", get_a())
validate("expected b", get_b())
validate("expected c", get_c())
print("Done!")
def validate(expected, actual):
if expected != actual:
robot.api.fail("Unfortunately a '!=' moment was detected in your code 😳")(from #4237 (comment))
Being able to log multiple individual failure messages under a single keyword could be nice, though. That we could easily support by making it possible to raise an exception so that its message is actually a list of messages. In the simplest form it could just mean
AssertiongError(['First error', 'Second error']). We could log each error separately and then generate "Several failures occurred" error based on the errors automatically. This would be easy to implement and doesn't have that much to do with an API to run other keywords. It would need its own issue, though, so please submit one!

Activity
pekkaklarck commentedon Mar 15, 2022
If I understand this correctly, the idea is to report multiple errors from one keyword so that
If the above is the use case, what's proposed looks really complicated to use and to implement. I don't understand why this would require adding both
continue_on_failurescontext manager an newrobot.api.failmethod. Could you are both needed or what the API should be?pekkaklarck commentedon Mar 15, 2022
As you probably already noticed, I submitted #4277 about an alternative way to report multiple failures. That approach would be easier to use because you would use
raise AssertionError(...)as with normal failures and it ought to be pretty easy to implement as well. The only downside I see compared to what's proposed here is that it doesn't, in the current form, support accurate timestamps with each failure.KotlinIsland commentedon Mar 15, 2022
I'm just providing possible solutions, I have custom functionality for both approaches.
I think that preserving log order is highly important. Also I can see that your approach would involve heavy boilerplate with high potential for inadvertently introducing bugs.
pekkaklarck commentedon Mar 15, 2022
Do you mean both
continue_on_failuresandrobot.api.failwould be need to accomplish this or that they would provide two alternative ways to do that? I value your proposals, but I would very highly appreciate if you could spend a bit longer time describing them so that it would be easier for me to understand them.KotlinIsland commentedon Mar 15, 2022
Yeah, two different approaches. Sorry about that, I'll update the OP
pekkaklarck commentedon Mar 15, 2022
Do you want both or are you just proposing two alternatives?
KotlinIsland commentedon Mar 15, 2022
I have both and tend to use the context manager solution a lot more, but it's entirely up to you 😀.
I have sub-typed
BuiltInand wrapped all the assertion function in this custom failure mechanism I have made.KotlinIsland commentedon Mar 15, 2022
And maybe my ideas aren't optimal, but hopefully they add to the general discussion.
pekkaklarck commentedon Mar 15, 2022
So the main idea is adding
robot.api.fail()that can be called withcontinue=Trueto make the failure continuable? And thenrobot.api.continue_on_failurescontext manager would just change the default behavior ofrobot.api.fail?pekkaklarck commentedon Mar 15, 2022
Do you have implementation somewhere so that I could look at what you've actually done? I cannot think any really clean way how to implement this exact API. I do have an idea about a similar API that could probably be implemented pretty easily and cleanly.
pekkaklarck commentedon Mar 15, 2022
Here's an example of using an API that ought to be pretty easy to implement:
The idea is that the
failure_reportercontext manager would support reporting failures so that they are handled immediately. In its__exit__it would then check were any failures reported and raise an exception if here were. The context manager itself would be easy to implement otherwise, but we needed to exposefailso that it could be used by libraries.This API could be even nice to use:
Now
loggeritself would getfailfunction. It could just raise AssertionError by default, butcontinue_on_failurecontext manager would change the behavior. The annoying thing here is that becauseloggeris a module, this approach would require storing some information in module global state. That's not nice in general and it would cause problems with threads.pekkaklarck commentedon May 20, 2025
Simply collecting all failures within a keyword and reporting them in one go is so easy that adding built-in functionality to Robot isn't, in my opinion, worth the effort amd added complexity.