Robot Framework
testsuite.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.utils import setter
17 
18 from .configurer import SuiteConfigurer
19 from .filter import Filter, EmptySuiteRemover
20 from .fixture import create_fixture
21 from .itemlist import ItemList
22 from .keyword import Keyword, Keywords
23 from .metadata import Metadata
24 from .modelobject import ModelObject
25 from .tagsetter import TagSetter
26 from .testcase import TestCase, TestCases
27 
28 
29 
35  test_class = TestCase #: Internal usage only.
36  fixture_class = Keyword #: Internal usage only.
37  repr_args = ('name',)
38  __slots__ = ['parent', 'source', '_name', 'doc', '_setup', '_teardown', 'rpa',
39  '_my_visitors']
40 
41  def __init__(self, name='', doc='', metadata=None, source=None, rpa=False,
42  parent=None):
43  self._name_name = name
44  self.docdoc = doc
45  self.metadatametadatametadata = metadata
46  self.sourcesource = source #: Path to the source file or directory.
47  self.parentparent = parent #: Parent suite. ``None`` with the root suite.
48  self.rparpa = rpa #: ``True`` when RPA mode is enabled.
49  self.suitessuitessuites = None
50  self.teststeststests = None
51  self._setup_setup = None
52  self._teardown_teardown = None
53  self._my_visitors_my_visitors = []
54 
55  @property
56  _visitors = property
57 
58  def _visitors(self):
59  parent_visitors = self.parentparent._visitors if self.parentparent else []
60  return self._my_visitors_my_visitors + parent_visitors
61 
62  @property
63 
64  name = property
65 
66  def name(self):
67  return self._name_name or ' & '.join(s.name for s in self.suitessuitessuites)
68 
69  @name.setter
70 
71  def name(self, name):
72  self._name_name = name
73 
74  @property
75 
76  longname = property
77 
78  def longname(self):
79  if not self.parentparent:
80  return self.namenamenamename
81  return '%s.%s' % (self.parentparent.longname, self.namenamenamename)
82 
83  @setter
84 
85  def metadata(self, metadata):
86  return Metadata(metadata)
87 
88  @setter
89 
90  def suites(self, suites):
91  return TestSuites(self.__class__, self, suites)
92 
93  @setter
94 
95  def tests(self, tests):
96  return TestCases(self.test_classtest_class, self, tests)
97 
98  @property
99 
122  setup = property
123 
124  def setup(self):
125  if self._setup_setup is None and self:
126  self._setup_setup = create_fixture(None, self, Keyword.SETUP)
127  return self._setup_setup
128 
129  @setup.setter
130 
131  def setup(self, setup):
132  self._setup_setup = create_fixture(setup, self, Keyword.SETUP)
133 
134  @property
135 
145  has_setup = property
146 
147  def has_setup(self):
148 
149  return bool(self._setup_setup)
150 
151  @property
152 
156  teardown = property
157 
158  def teardown(self):
159  if self._teardown_teardown is None and self:
160  self._teardown_teardown = create_fixture(None, self, Keyword.TEARDOWN)
161  return self._teardown_teardown
162 
163  @teardown.setter
164 
165  def teardown(self, teardown):
166  self._teardown_teardown = create_fixture(teardown, self, Keyword.TEARDOWN)
167 
168  @property
169 
175  has_teardown = property
176 
177  def has_teardown(self):
178  return bool(self._teardown_teardown)
179 
180  @property
181 
185  keywords = property
186 
187  def keywords(self):
188  keywords = [self.setupsetupsetupsetup, self.teardownteardownteardownteardown]
189  return Keywords(self, [kw for kw in keywords if kw])
190 
191  @keywords.setter
192 
193  def keywords(self, keywords):
194  Keywords.raise_deprecation_error()
195 
196  @property
197 
207  id = property
208 
209  def id(self):
210  if not self.parentparent:
211  return 's1'
212  return '%s-s%d' % (self.parentparent.id, self.parentparent.suites.index(self)+1)
213 
214  @property
215 
216  test_count = property
217 
218  def test_count(self):
219  return len(self.teststeststests) + sum(suite.test_count for suite in self.suitessuitessuites)
220 
221  @property
222  has_tests = property
223 
224  def has_tests(self):
225  if self.teststeststests:
226  return True
227  return any(s.has_tests for s in self.suitessuitessuites)
228 
229 
238  def set_tags(self, add=None, remove=None, persist=False):
239  setter = TagSetter(add, remove)
240  self.visitvisit(setter)
241  if persist:
242  self._my_visitors_my_visitors.append(setter)
243 
244 
259  def filter(self, included_suites=None, included_tests=None,
260  included_tags=None, excluded_tags=None):
261  self.visitvisit(Filter(included_suites, included_tests,
262  included_tags, excluded_tags))
263 
264 
276  def configure(self, **options):
277  if self.parentparent is not None:
278  raise ValueError("'TestSuite.configure()' can only be used with "
279  "the root test suite.")
280  if options:
281  self.visitvisit(SuiteConfigurer(**options))
282 
283 
284  def remove_empty_suites(self, preserve_direct_children=False):
285  self.visitvisit(EmptySuiteRemover(preserve_direct_children))
286 
287 
288  def visit(self, visitor):
289  visitor.visit_suite(self)
290 
291  def __str__(self):
292  return self.namenamenamename
293 
294 
296  __slots__ = []
297 
298  def __init__(self, suite_class=TestSuite, parent=None, suites=None):
299  ItemList.__init__(self, suite_class, {'parent': parent}, suites)
A list-like object representing keywords in a suite, a test or a keyword.
Definition: keyword.py:137
Base model for single suite.
Definition: testsuite.py:34
teardown
Suite teardown as a :class:~.model.keyword.Keyword object.
Definition: testsuite.py:156
has_setup
Check does a suite have a setup without creating a setup object.
Definition: testsuite.py:145
def suites(self, suites)
Child suites as a :class:~.TestSuites object.
Definition: testsuite.py:90
def remove_empty_suites(self, preserve_direct_children=False)
Removes all child suites not containing any tests, recursively.
Definition: testsuite.py:284
id
An automatically generated unique id.
Definition: testsuite.py:207
keywords
Deprecated since Robot Framework 4.0.
Definition: testsuite.py:185
test_count
Number of the tests in this suite, recursively.
Definition: testsuite.py:216
def metadata(self, metadata)
Free test suite metadata as a dictionary.
Definition: testsuite.py:85
def visit(self, visitor)
:mod:Visitor interface <robot.model.visitor> entry-point.
Definition: testsuite.py:288
def set_tags(self, add=None, remove=None, persist=False)
Add and/or remove specified tags to the tests in this suite.
Definition: testsuite.py:238
def tests(self, tests)
Tests as a :class:~.TestCases object.
Definition: testsuite.py:95
def teardown(self, teardown)
Definition: testsuite.py:165
setup
Suite setup as a :class:~.model.keyword.Keyword object.
Definition: testsuite.py:122
def configure(self, **options)
A shortcut to configure a suite using one method call.
Definition: testsuite.py:276
def filter(self, included_suites=None, included_tests=None, included_tags=None, excluded_tags=None)
Select test cases and remove others from this suite.
Definition: testsuite.py:260
def __init__(self, name='', doc='', metadata=None, source=None, rpa=False, parent=None)
Definition: testsuite.py:42
has_teardown
Check does a suite have a teardown without creating a teardown object.
Definition: testsuite.py:175
longname
Suite name prefixed with the long name of the parent suite.
Definition: testsuite.py:76
def __init__(self, suite_class=TestSuite, parent=None, suites=None)
Definition: testsuite.py:298
def create_fixture(fixture, parent, type)
Definition: fixture.py:16