Skip to content

Commit ef8a635

Browse files
authored
plugin module refactoring
1 parent 00c29f4 commit ef8a635

File tree

8 files changed

+391
-236
lines changed

8 files changed

+391
-236
lines changed

pytest_reportportal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
from .rp_logging import RPLogger, RPLogHandler
44

5-
__all__ = ['RPLogger', 'RPLogHandler']
5+
__all__ = ['LAUNCH_WAIT_TIMEOUT', 'RPLogger', 'RPLogHandler']
66

77
LAUNCH_WAIT_TIMEOUT = 10

pytest_reportportal/config.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""This module contains class that stores RP agent configuration data."""
2+
3+
from os import getenv
4+
5+
try:
6+
# This try/except can go away once we support pytest >= 5.4.0
7+
from _pytest.logging import get_actual_log_level
8+
except ImportError:
9+
from _pytest.logging import get_log_level_for_setting as \
10+
get_actual_log_level
11+
12+
13+
class AgentConfig(object):
14+
"""Storage for the RP agent initialization attributes."""
15+
16+
def __init__(self, pytest_config):
17+
"""Initialize required attributes."""
18+
self._rp_rerun = None
19+
self.pconfig = pytest_config
20+
21+
self.rp_endpoint = self.pconfig.getini('rp_endpoint')
22+
self.rp_ignore_errors = bool(self.pconfig.getini('rp_ignore_errors'))
23+
self.rp_ignore_attributes = self.pconfig.getini('rp_ignore_attributes')
24+
self.rp_launch = self.pconfig.option.rp_launch or self.pconfig.getini(
25+
'rp_launch')
26+
self.rp_launch_id = (self.pconfig.option.rp_launch_id or
27+
self.pconfig.getini('rp_launch_id'))
28+
self.rp_launch_attributes = self.pconfig.getini('rp_launch_attributes')
29+
self.rp_launch_description = (
30+
self.pconfig.option.rp_launch_description or
31+
self.pconfig.getini('rp_launch_description')
32+
)
33+
self.rp_log_batch_size = int(self.pconfig.getini('rp_log_batch_size'))
34+
self.rp_log_level = get_actual_log_level(self.pconfig, 'rp_log_level')
35+
self.rp_parent_item_id = (self.pconfig.option.rp_parent_item_id or
36+
self.pconfig.getini('rp_parent_item_id'))
37+
self.rp_project = (self.pconfig.option.rp_project or
38+
self.pconfig.getini('rp_project'))
39+
self.rp_rerun_of = (self.pconfig.option.rp_rerun_of or
40+
self.pconfig.getini('rp_rerun_of'))
41+
self.rp_retries = int(self.pconfig.getini('retries'))
42+
self.rp_uuid = getenv('RP_UUID') or self.pconfig.getini('rp_uuid')
43+
self.rp_verify_ssl = self.pconfig.getini('rp_verify_ssl')
44+
45+
@property
46+
def rp_rerun(self):
47+
"""Get value of the rp_rerun parameter."""
48+
if self._rp_rerun is None:
49+
if self.rp_rerun_of:
50+
self._rp_rerun = True
51+
else:
52+
self._rp_rerun = (self.pconfig.option.rp_rerun or
53+
self.pconfig.getini('rp_rerun'))
54+
return self._rp_rerun

pytest_reportportal/config.pyi

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from _pytest.config import Config as Config
2+
from typing import List, Optional, Text
3+
4+
class AgentConfig:
5+
_rp_rerun: Optional[bool] = ...
6+
pconfig: Config = ...
7+
rp_endpoint: Text = ...
8+
rp_ignore_errors: bool = ...
9+
rp_ignore_attributes: Optional[List] = ...
10+
rp_launch: Text = ...
11+
rp_launch_id: Optional[Text] = ...
12+
rp_launch_attributes: Optional[List] = ...
13+
rp_launch_description: Text = ...
14+
rp_log_batch_size: int = ...
15+
rp_log_level: Optional[int] = ...
16+
rp_parent_item_id: Optional[Text] = ...
17+
rp_project: Text = ...
18+
rp_rerun_of: Optional[Text] = ...
19+
rp_retries: int = ...
20+
rp_uuid: Text = ...
21+
rp_verify_ssl: bool = ...
22+
def __init__(self, pytest_config: Config) -> None: ...
23+
@property
24+
def rp_rerun(self) -> Optional[bool]: ...

0 commit comments

Comments
 (0)