Skip to content

Commit fbfda6c

Browse files
committed
Enhance new Run Keyword And Warn On Failure a bit. robotframework#2294
- Include the name of the failed keyword in the warning. - Doc tuning. - Directly use Run Keyword And Ingore Error internally.
1 parent 243bfcd commit fbfda6c

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

atest/robot/standard_libraries/builtin/run_keyword_and_warn_on_failure.robot

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,30 @@ Resource atest_resource.robot
55
*** Test Cases ***
66
Run Keyword And Warn On Failure
77
${tc}= Check Test Case ${TESTNAME}
8-
Check Log Message ${tc.kws[0].msgs[0]} Expected Warn WARN
8+
Check Log Message ${tc.kws[0].msgs[0]} Executing keyword 'FAIL' failed:\nExpected Warn WARN
99

1010
Run Keyword And Warn On Failure For Keyword Teardown
1111
${tc}= Check Test Case ${TESTNAME}
12-
Check Log Message ${tc.kws[0].msgs[0]} Keyword teardown failed:\nExpected Warn From User Keyword Teardown WARN
12+
Check Log Message ${tc.kws[0].msgs[0]}
13+
... Executing keyword 'Failing Keyword Teardown' failed:\nKeyword teardown failed:\nExpected WARN
1314

1415
Run User keyword And Warn On Failure
1516
${tc}= Check Test Case ${TESTNAME}
16-
Check Log Message ${tc.kws[0].msgs[0]} Expected Warn In User Keyword WARN
17+
Check Log Message ${tc.kws[0].msgs[0]}
18+
... Executing keyword 'Exception In User Defined Keyword' failed:\nExpected Warn In User Keyword WARN
1719

1820
Run Keyword And Warn On Failure With Syntax Error
1921
Check Test Case ${TESTNAME}
2022

2123
Run Keyword And Warn On Failure With Failure On Test Teardown
2224
${tc}= Check Test Case ${TESTNAME}
23-
Check Log Message ${tc.teardown.msgs[0]} Expected Warn From Test Teardown WARN
25+
Check Log Message ${tc.teardown.msgs[0]}
26+
... Executing keyword 'Should Be Equal' failed:\nx != y WARN
2427

2528
Run Keyword And Warn On Failure With Timeout
2629
Check Test Case ${TESTNAME}
2730

2831
Run Keyword And Warn On Failure On Suite Teardown
2932
${suite} = Get Test Suite Run Keyword And Warn On Failure
30-
Check Log Message ${suite.teardown.msgs[0]} Expected Warn From Suite Teardown WARN
33+
Check Log Message ${suite.teardown.msgs[0]}
34+
... Executing keyword 'Fail' failed:\nExpected Warn From Suite Teardown WARN

atest/testdata/standard_libraries/builtin/run_keyword_and_warn_on_failure.robot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Run Keyword And Warn On Failure
99

1010
Run Keyword And Warn On Failure For Keyword Teardown
1111
[Documentation] PASS
12-
Run Keyword And Warn On Failure User Keyword With Failing Teardown
12+
Run Keyword And Warn On Failure Failing Keyword Teardown
1313
Log This Should Be Executed
1414

1515
Run User keyword And Warn On Failure
@@ -24,7 +24,7 @@ Run Keyword And Warn On Failure With Syntax Error
2424

2525
Run Keyword And Warn On Failure With Failure On Test Teardown
2626
[Documentation] PASS
27-
[Teardown] Run Keyword And Warn On Failure Fail Expected Warn From Test Teardown
27+
[Teardown] Run Keyword And Warn On Failure Should Be Equal x y
2828
Log This should Be Executed
2929

3030
Run Keyword And Warn On Failure With Timeout
@@ -34,9 +34,9 @@ Run Keyword And Warn On Failure With Timeout
3434
Fail This Should Not Be Executed!
3535

3636
*** Keywords ***
37-
User Keyword With Failing Teardown
37+
Failing Keyword Teardown
3838
No Operation
39-
[Teardown] Fail Expected Warn From User Keyword Teardown
39+
[Teardown] Fail Expected
4040

4141
Exception In User Defined Keyword
4242
Fail Expected Warn In User Keyword

src/robot/libraries/BuiltIn.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,24 +1851,22 @@ def run_keyword_and_ignore_error(self, name, *args):
18511851

18521852
@run_keyword_variant(resolve=1)
18531853
def run_keyword_and_warn_on_failure(self, name, *args):
1854-
""" Runs the given keyword with given arguments and returns a warning in case of an error.
1854+
"""Runs the specified keyword logs a warning if the keyword fails.
18551855
1856-
This keyword is similar with `Run Keyword And Ignore Error` but in addition it logs the error messages as
1857-
warnings. See `Run Keyword And Ignore Error` documentation for more details.
1856+
This keyword is similar to `Run Keyword And Ignore Error` but if the executed
1857+
keyword fails, the error message is logged as a warning to make it more
1858+
visible. Returns status and possible return value or error message exactly
1859+
like `Run Keyword And Ignore Error` does.
18581860
18591861
Errors caused by invalid syntax, timeouts, or fatal exceptions are not
18601862
caught by this keyword. Otherwise this keyword itself never fails.
18611863
18621864
New in Robot Framework 4.0.
18631865
"""
1864-
try:
1865-
return 'PASS', self.run_keyword(name, *args)
1866-
except ExecutionFailed as err:
1867-
if err.dont_continue:
1868-
raise
1869-
1870-
logger.warn(err)
1871-
return 'FAIL', unic(err)
1866+
status, message = self.run_keyword_and_ignore_error(name, *args)
1867+
if status == 'FAIL':
1868+
logger.warn("Executing keyword '%s' failed:\n%s" % (name, message))
1869+
return status, message
18721870

18731871
@run_keyword_variant(resolve=1)
18741872
def run_keyword_and_return_status(self, name, *args):

0 commit comments

Comments
 (0)