Skip to content

Commit

Permalink
Add TestDefaults.set_to.
Browse files Browse the repository at this point in the history
Makes it easier for custom parsers (#1283) to set defaults to test.
  • Loading branch information
pekkaklarck committed Apr 26, 2023
1 parent caa8c3a commit cf0cdca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 1 addition & 4 deletions atest/testdata/parsing/custom/CustomParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ def parse(self, source: Path, defaults: TestDefaults) -> TestSuite:
return 'bad'
suite = custom.parse(source)
for test in suite.tests:
test.tags += defaults.tags
test.setup = defaults.setup
test.teardown = defaults.teardown
test.timeout = defaults.timeout
defaults.set_to(test)
return suite

def parse_init(self, source: Path, defaults: TestDefaults) -> TestSuite:
Expand Down
17 changes: 16 additions & 1 deletion src/robot/running/builder/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from robot.model import Tags

from ..model import Keyword
from ..model import Keyword, TestCase


class KeywordDict(TypedDict):
Expand Down Expand Up @@ -111,6 +111,21 @@ def timeout(self) -> 'str|None':
def timeout(self, timeout: 'str|None'):
self._timeout = timeout

def set_to(self, test: TestCase):
"""Sets defaults to the given test.
Tags are always added to the test. Setup, teardown and timeout are
set only if the test does not have them set initially.
"""
if self.tags:
test.tags += self.tags
if self.setup and not test.has_setup:
test.setup = self.setup
if self.teardown and not test.has_teardown:
test.teardown = self.teardown
if self.timeout and not test.timeout:
test.timeout = self.timeout


class FileSettings:

Expand Down

0 comments on commit cf0cdca

Please sign in to comment.