robotframework: Support method of failing current keyword/test and continuing in python
I have a Python function keyword described as A context manager that runs as a Robot keyword that supports continue on error.
@keyword
def test(): # will show as passed in log
with keyword("will fail", continue_on_error=True): # will show as failed in log and will fail the test
BuiltIn().fail("foo")
logger.info("bar") # will run
But the report looks janky because it doesn’t make test failed and the error needs to be raised in cleanup.
I guess it boils down to: I want a pure python implementation of “Run Keyword And Continue On Failure”
Here’s a rough implementation of keyword:
from contextlib import contextmanager
from robot.libraries.BuiltIn import BuiltIn
from robot.running.statusreporter import StatusReporter
exception_store = None
@contextmanager
def keyword(name, continue_on_error=False):
"""A context manager that runs as a Robot keyword
continue_on_error: if an error occurs in this keyword, exit and report as failed but continue test
"""
try:
with StatusReporter(BuiltIn()._context, Keyword(kwname=name)):
yield
except Exception as err:
if continue_on_error:
global exception_store
exception_store = err
return
raise err
def cleanup():
if exception_store:
raise exception_store
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 17 (17 by maintainers)
@pekkaklarck I think I’ve found a way to get the desired outcome, does this look right to you?