Revision: 3191
Author: pekka.klarck
Date: Wed May  5 09:40:19 2010
Log: 1) Moved checking can execution be continued to better place, 2) The change in 1) fixes setting variables in teardown when the keyword fails, 3) Don't allow continuing if timeout or syntax error occurred
http://code.google.com/p/robotframework/source/detail?r=3191

Modified:
 /trunk/atest/robot/running/errors_in_test_teardown.txt
 /trunk/atest/testdata/running/errors_in_test_teardown.txt
 /trunk/src/robot/errors.py
 /trunk/src/robot/running/keywords.py

=======================================
--- /trunk/atest/robot/running/errors_in_test_teardown.txt Wed May 5 07:29:49 2010 +++ /trunk/atest/robot/running/errors_in_test_teardown.txt Wed May 5 09:40:19 2010
@@ -1,23 +1,32 @@
-*** Settings ***
+*** Settings ***
 Suite Setup     Run Tests  ${EMPTY}  running/errors_in_test_teardown.txt
 Force Tags      regression  pybot  jybot
 Resource        atest_resource.txt

 *** Test Cases ***
-Test With One Error In Teardown
+One Error In Teardown
     ${tc} =  Check Test Case  ${TESTNAME}
Check Log Message ${tc.teardown.kws[1].msgs[0]} This Should Be executed

-Test With Many Errors In Teardown
+Many Errors In Teardown
     ${tc} =  Check Test Case  ${TESTNAME}
Check Log Message ${tc.teardown.kws[2].msgs[0]} This Should Also Be Executed

-Test With A Fatal Error In Teardown
+Errors In Teardown When Setting Variables
+    ${tc} =  Check Test Case  ${TESTNAME}
+ Check Log Message ${tc.teardown.kws[0].msgs[0]} no return value is set FAIL
+    Check Log Message  ${tc.teardown.kws[0].msgs[1]}  \${ret} = None
+
+Errors In For Loop In Teardown
+    Check Test Case  ${TESTNAME}
+
+Keyword Timeout In Teardown
     ${tc} =  Check Test Case  ${TESTNAME}
     Should Be True  len(${tc.teardown.kws}) == 1

-Test With Errors In For Loop In Teardown
+Fatal Error In Teardown
     ${tc} =  Check Test Case  ${TESTNAME}
+    Should Be True  len(${tc.teardown.kws}) == 1

 Suite Teardown Is Executed Fully
     ${ts} =  Get Test Suite  errors in test teardown
=======================================
--- /trunk/atest/testdata/running/errors_in_test_teardown.txt Wed May 5 07:29:49 2010 +++ /trunk/atest/testdata/running/errors_in_test_teardown.txt Wed May 5 09:40:19 2010
@@ -1,16 +1,16 @@
-*** Settings ***
+*** Settings ***
 Library  Exceptions
 Suite Teardown  Suite Teardown With Errors

 *** Test Cases ***
-Test With One Error In Teardown
+One Error In Teardown
     [documentation]  FAIL Teardown failed:\n
     ...  Message\n\n
     ...  Also teardown of the parent suite failed.
     No Operation
     [teardown]  One Error

-Test With Many Errors In Teardown
+Many Errors In Teardown
     [documentation]  FAIL Teardown failed:\n
     ...  Several failures occurred:\n\n
     ...  1) Message 1\n\n
@@ -19,7 +19,14 @@
     No Operation
     [teardown]  Many Errors

-Test With Errors In For Loop In Teardown
+Errors In Teardown When Setting Variables
+    [documentation]  FAIL  Teardown failed:\n
+    ...  no return value is set\n\n
+    ...  Also teardown of the parent suite failed.
+    No Operation
+    [teardown]  Errors when setting variables
+
+Errors In For Loop In Teardown
     [documentation]  FAIL Teardown failed:\n
     ...  Several failures occurred:\n\n
     ...  1) cat\n\n
@@ -30,13 +37,21 @@
     No Operation
     [teardown]  Errors In For Loop

-Test With A Fatal Error In Teardown
+Keyword Timeout In Teardown
+    [documentation]  FAIL Teardown failed:\n
+    ...  Keyword timeout 42 milliseconds exceeded.\n\n
+    ...  Also teardown of the parent suite failed.
+    No Operation
+    [teardown]  Timeout
+
+Fatal Error In Teardown
     [documentation]  FAIL Teardown failed:\n
     ...  FatalCatastrophyException\n\n
     ...  Also teardown of the parent suite failed.
     No Operation
     [teardown]  Fatal Error

+
 *** Keywords ***
 One Error
     Fail  Message
@@ -46,6 +61,10 @@
     Fail  Message 1
     Fail  Message 2
     Log  This Should Also Be Executed
+
+Errors when setting variables
+    ${ret} =  Fail  no return value is set
+    Should Be Equal  ${ret}  ${None}

 Errors In For Loop
     :FOR  ${animal}  in  cat  dog
@@ -54,7 +73,12 @@

 Fatal Error
     Exit On Failure
-    Log  This Should Not Be Executed
+    Fail  This Should Not Be Executed
+
+Timeout
+    [timeout]  42 ms
+    Sleep  1 s
+    Fail  This Should Not Be Executed

 Suite Teardown With Errors
     Fail  Suite Message 1
=======================================
--- /trunk/src/robot/errors.py  Wed May  5 03:26:53 2010
+++ /trunk/src/robot/errors.py  Wed May  5 09:40:19 2010
@@ -60,8 +60,20 @@
         RobotError.__init__(self, utils.cut_long_message(message))
         self.timeout = timeout
         self.exit = exit
-        self.cont = cont
         self.syntax = syntax
+        self.cont = self._continue_on_failure(cont)
+
+    def _continue_on_failure(self, cont):
+        if self.timeout or self.syntax or self.exit:
+            return False
+        if cont:
+            return True
+        return self._in_test_or_suite_teardown()
+
+    def _in_test_or_suite_teardown(self):
+        from robot.running import NAMESPACES
+        test_or_suite = NAMESPACES.current.test or NAMESPACES.current.suite
+        return test_or_suite.status != 'RUNNING'

     def get_errors(self):
         return [self]
=======================================
--- /trunk/src/robot/running/keywords.py        Wed May  5 07:23:13 2010
+++ /trunk/src/robot/running/keywords.py        Wed May  5 09:40:19 2010
@@ -30,25 +30,11 @@
                 kw.run(output, namespace)
             except ExecutionFailed, err:
                 errors.extend(err.get_errors())
-                if not self._continue_on_failure(err):
+                if not err.cont:
                     break
         if errors:
             raise ExecutionFailures(errors)

-    def _continue_on_failure(self, err):
-        if err.exit:
-            return False
-        if err.cont:
-            return True
-        if self._in_test_or_suite_teardown():
-            err.cont = True
-        return err.cont
-
-    def _in_test_or_suite_teardown(self):
-        from robot.running import NAMESPACES
-        test_or_suite = NAMESPACES.current.test or NAMESPACES.current.suite
-        return test_or_suite.status != 'RUNNING'
-
     def __nonzero__(self):
         return bool(self._keywords)

Reply via email to