|
| 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 |
0 commit comments