Robot Framework
gatherfailed.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.errors import DataError
17 from robot.model import SuiteVisitor
18 from robot.result import ExecutionResult
19 from robot.utils import get_error_message, glob_escape
20 
21 
22 class GatherFailedTests(SuiteVisitor):
23 
24  def __init__(self):
25  self.teststests = []
26 
27  def visit_test(self, test):
28  if test.failed:
29  self.teststests.append(glob_escape(test.longname))
30 
31  def visit_keyword(self, kw):
32  pass
33 
34 
35 class GatherFailedSuites(SuiteVisitor):
36 
37  def __init__(self):
38  self.suitessuites = []
39 
40  def start_suite(self, suite):
41  if any(test.failed for test in suite.tests):
42  self.suitessuites.append(glob_escape(suite.longname))
43 
44  def visit_test(self, test):
45  pass
46 
47  def visit_keyword(self, kw):
48  pass
49 
50 
51 def gather_failed_tests(output, empty_suite_ok=False):
52  if output is None:
53  return None
54  gatherer = GatherFailedTests()
55  tests_or_tasks = 'tests or tasks'
56  try:
57  suite = ExecutionResult(output, include_keywords=False).suite
58  suite.visit(gatherer)
59  tests_or_tasks = 'tests' if not suite.rpa else 'tasks'
60  if not gatherer.tests and not empty_suite_ok:
61  raise DataError('All %s passed.' % tests_or_tasks)
62  except Exception:
63  raise DataError("Collecting failed %s from '%s' failed: %s"
64  % (tests_or_tasks, output, get_error_message()))
65  return gatherer.tests
66 
67 
68 def gather_failed_suites(output, empty_suite_ok=False):
69  if output is None:
70  return None
71  gatherer = GatherFailedSuites()
72  try:
73  ExecutionResult(output, include_keywords=False).suite.visit(gatherer)
74  if not gatherer.suites and not empty_suite_ok:
75  raise DataError('All suites passed.')
76  except Exception:
77  raise DataError("Collecting failed suites from '%s' failed: %s"
78  % (output, get_error_message()))
79  return gatherer.suites
def gather_failed_tests(output, empty_suite_ok=False)
Definition: gatherfailed.py:51
def gather_failed_suites(output, empty_suite_ok=False)
Definition: gatherfailed.py:68
def ExecutionResult(*sources, **options)
Factory method to constructs :class:~.executionresult.Result objects.
def get_error_message()
Returns error message of the last occurred exception.
Definition: error.py:34
def glob_escape(item)
Definition: escaping.py:42