Robot Framework
suiteteardownfailed.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from robot.model import SuiteVisitor
17 
18 
20 
21  def end_suite(self, suite):
22  teardown = suite.teardown
23  # Both 'PASS' and 'NOT RUN' statuses are OK.
24  if teardown and teardown.status == teardown.FAIL:
25  suite.suite_teardown_failed(teardown.message)
26  if teardown and teardown.status == teardown.SKIP:
27  suite.suite_teardown_skipped(teardown.message)
28 
29  def visit_test(self, test):
30  pass
31 
32  def visit_keyword(self, keyword):
33  pass
34 
35 
36 class SuiteTeardownFailed(SuiteVisitor):
37 
40  _normal_msg = 'Parent suite teardown failed:\n%s'
41 
44  _also_msg = '\n\nAlso parent suite teardown failed:\n%s'
45 
48  _normal_skip_msg = 'Skipped in parent suite teardown:\n%s'
49 
52  _also_skip_msg = 'Skipped in parent suite teardown:\n%s\n\nEarlier message:\n%s'
53 
54  def __init__(self, message, skipped=False):
55  self.messagemessage = message
56  self.skippedskipped = skipped
57 
58  def visit_test(self, test):
59  if not self.skippedskipped:
60  self._suite_teardown_failed_suite_teardown_failed(test)
61  else:
62  self._suite_teardown_skipped_suite_teardown_skipped(test)
63 
64  def _suite_teardown_failed(self, test):
65  if not test.skipped:
66  test.status = test.FAIL
67  prefix = self._also_msg_also_msg if test.message else self._normal_msg_normal_msg
68  test.message += prefix % self.messagemessage
69 
70  def _suite_teardown_skipped(self, test):
71  test.status = test.SKIP
72  if test.message:
73  test.message = self._also_skip_msg_also_skip_msg % (self.messagemessage, test.message)
74  else:
75  test.message = self._normal_skip_msg_normal_skip_msg % self.messagemessage
76 
77  def visit_keyword(self, keyword):
78  pass
Interface to ease traversing through a test suite structure.
Definition: visitor.py:85
def visit_keyword(self, keyword)
Implements traversing through keywords.
def visit_test(self, test)
Implements traversing through tests.
def visit_keyword(self, keyword)
Implements traversing through keywords.
def visit_test(self, test)
Implements traversing through tests.