-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathrobot_runner.py
More file actions
123 lines (109 loc) · 4.72 KB
/
robot_runner.py
File metadata and controls
123 lines (109 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from __future__ import annotations
import robot
from pytest import FixtureRequest, Pytester
from tests.e2e import AllureFrameworkRunner, PathlikeT
from typing import Sequence, Mapping
from allure_robotframework import allure_robotframework
class AllureRobotRunner(AllureFrameworkRunner):
"""The runner to test allure-robotframework integration."""
LOGGER_PATH = "allure_robotframework.robot_listener.AllureFileLogger"
def __init__(self, request: FixtureRequest, pytester: Pytester):
super().__init__(request, pytester, AllureRobotRunner.LOGGER_PATH)
self.rootdir: str | None = None
def run_robotframework(
self,
suite_paths: Sequence[PathlikeT] = None,
suite_literals: Mapping[str, str] = None,
suite_rst_ids: Sequence[str] = None,
library_paths: Sequence[PathlikeT] = None,
library_literals: Mapping[str, str] = None,
library_rst_ids: Sequence[str] = None,
testplan_content: dict = None,
testplan_path: PathlikeT = None,
testplan_rst_id: str = None,
options: Mapping[str, any] = None
) -> None:
"""Runs the robotframework against an example.
The example consists of suite(s), i.e., .robot files, libraries,
i.e., .py files and, optionaly, a testplan. All types of files can be
specified either as paths or as a mapping from a file name to its content
or as a mapping from a file name to an ID in the associated .rst
document.
Arguments:
suite_paths (Sequence[str | Path]): a sequence of path-like objects
pointing to .robot files relative to the current test`s folder.
suite_literals (Mapping[str, str]): a mapping from a file name to
the content of a .robot file (.robot extension can be omitted).
suite_rst_ids (Mapping[str, str]): a mapping from a file name to an
ID of a .robot file content from the .rst document, associated
with current node.
library_paths (Sequence[str | Path]): a sequence of path-like
objects pointing to .py library files relative to the current
test`s folder.
library_literals (Mapping[str, str]): a mapping from a file name to
the content of a .py library file (.py extension can be
omitted).
library_rst_ids (Mapping[str, str]): a mapping from a file name to
an IDs of a .py library file content from the .rst document,
associated with current node.
testplan (dict): a testplan content.
testplan_path (str | Path): a path to a testplan relative to the
current test`s folder.
testplan_rst_id (str): a testplan ID from the .rst document,
associated with current node.
options (Mapping[str, any]): robot framework options.
Returns:
allure_commons.logger.AllureMemoryLogger: the allure results of the
run. The results of the last run are also accessible through the
:attr:`allure_results` attribute.
"""
return self._run(
self.__prepare_example(
suite_literals=suite_literals,
suite_paths=suite_paths,
suite_rst_ids=suite_rst_ids,
library_literals=library_literals,
library_paths=library_paths,
library_rst_ids=library_rst_ids
),
testplan_content=testplan_content,
testplan_path=testplan_path,
testplan_rst_id=testplan_rst_id,
options=self.__resolve_options(options)
)
def _run_framework(self, suites, options):
robot.run(*[self.rootdir] if self.rootdir else suites, listener=allure_robotframework(None), **options)
def __resolve_options(self, options):
return {
** {
"log": None,
"loglevel": "DEBUG",
"report": None,
"output": None,
"extension": "robot",
"outputdir": str(self.pytester.path)
},
** (options or {})
}
def __prepare_example(
self,
suite_literals,
suite_paths,
suite_rst_ids,
library_literals,
library_paths,
library_rst_ids
):
suites = self._create_files(
extension=".robot",
paths=suite_paths,
literals=suite_literals,
rst_examples=suite_rst_ids
)
self._create_files(
paths=library_paths,
literals=library_literals,
rst_examples=library_rst_ids
)
return suites
__all__ = ["AllureRobotRunner"]