Robot Framework Integrated Development Environment (RIDE)
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 robotide.lib.robot.errors import DataError
17 from robotide.lib.robot.model import SuiteVisitor
18 from robotide.lib.robot.result import ExecutionResult
19 from robotide.lib.robot.utils import get_error_message
20 
21 
22 class GatherFailedTests(SuiteVisitor):
23 
24  def __init__(self):
25  self.teststests = []
26 
27  def visit_test(self, test):
28  if not test.passed:
29  self.teststests.append(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(not test.passed for test in suite.tests):
42  self.suitessuites.append(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):
52  if output.upper() == 'NONE':
53  return []
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:
61  raise DataError('All %s passed.' % tests_or_tasks)
62  except:
63  raise DataError("Collecting failed %s from '%s' failed: %s"
64  % (tests_or_tasks, output, get_error_message()))
65  return gatherer.tests
66 
67 
69  if output.upper() == 'NONE':
70  return []
71  gatherer = GatherFailedSuites()
72  try:
73  ExecutionResult(output, include_keywords=False).suite.visit(gatherer)
74  if not gatherer.suites:
75  raise DataError('All suites passed.')
76  except:
77  raise DataError("Collecting failed suites from '%s' failed: %s"
78  % (output, get_error_message()))
79  return gatherer.suites
Used when variable does not exist.
Definition: errors.py:67
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:41