diff --git a/atests/test_retry_mechanisms.robot b/atests/test_retry_mechanisms.robot index 342c8c7..34dbf4b 100644 --- a/atests/test_retry_mechanisms.robot +++ b/atests/test_retry_mechanisms.robot @@ -19,9 +19,9 @@ Test Global Retry Configuration ${config}= Get Retry Configuration Should Be Equal As Integers ${config}[max_retries] 5 Should Be Equal As Numbers ${config}[backoff_factor] 0.5 - Should Contain ${config}[retry_on_status] 500 - Should Contain ${config}[retry_on_status] 502 - Should Contain ${config}[retry_on_status] 503 + List Should Contain Value ${config}[retry_on_status] ${500} + List Should Contain Value ${config}[retry_on_status] ${502} + List Should Contain Value ${config}[retry_on_status] ${503} Test Session Retry Configuration [Documentation] Test setting session-specific retry configuration diff --git a/src/HttpxLibrary/RetryKeywords.py b/src/HttpxLibrary/RetryKeywords.py index df8a1da..379a64e 100644 --- a/src/HttpxLibrary/RetryKeywords.py +++ b/src/HttpxLibrary/RetryKeywords.py @@ -70,6 +70,12 @@ def set_global_retry_configuration(self, | Set Global Retry Configuration | max_retries=5 | backoff_factor=0.5 | | Set Global Retry Configuration | retry_on_status=500,502,503 | jitter=False | """ + # Convert parameters to correct types (Robot Framework passes everything as strings) + max_retries = int(max_retries) + backoff_factor = float(backoff_factor) + backoff_max = float(backoff_max) + jitter = bool(jitter) if isinstance(jitter, bool) else str(jitter).lower() in ('true', '1', 'yes') + if isinstance(retry_on_status, str): retry_on_status = [int(code.strip()) for code in retry_on_status.split(',')] @@ -107,6 +113,12 @@ def set_session_retry_configuration(self, | Set Session Retry Configuration | my_session | max_retries=5 | | Set Session Retry Configuration | api_session | retry_on_status=429,503 | backoff_factor=1.0 | """ + # Convert parameters to correct types (Robot Framework passes everything as strings) + max_retries = int(max_retries) + backoff_factor = float(backoff_factor) + backoff_max = float(backoff_max) + jitter = bool(jitter) if isinstance(jitter, bool) else str(jitter).lower() in ('true', '1', 'yes') + if isinstance(retry_on_status, str): retry_on_status = [int(code.strip()) for code in retry_on_status.split(',')] @@ -275,13 +287,22 @@ def retry_request_on_session(self, """ session = self._cache.switch(alias) - # Get base retry config and override if specified - retry_config = self._get_retry_config(alias) + # Get base retry config and create a copy to avoid modifying the original + base_config = self._get_retry_config(alias) + retry_config = RetryConfig( + max_retries=base_config.max_retries, + backoff_factor=base_config.backoff_factor, + backoff_max=base_config.backoff_max, + retry_on_status=base_config.retry_on_status.copy(), + retry_on_exceptions=base_config.retry_on_exceptions.copy(), + jitter=base_config.jitter + ) + # Override with request-specific parameters (convert types as needed) if max_retries is not None: - retry_config.max_retries = max_retries + retry_config.max_retries = int(max_retries) if backoff_factor is not None: - retry_config.backoff_factor = backoff_factor + retry_config.backoff_factor = float(backoff_factor) if retry_on_status is not None: if isinstance(retry_on_status, str): retry_config.retry_on_status = [int(code.strip()) for code in retry_on_status.split(',')] @@ -333,6 +354,12 @@ def wait_until_request_succeeds(self, | ${response}= | Wait Until Request Succeeds | my_session | GET | /health | | ${response}= | Wait Until Request Succeeds | my_session | GET | /api/ready | timeout=120 | interval=5 | """ + # Convert parameters to correct types (Robot Framework passes everything as strings) + timeout = float(timeout) + interval = float(interval) + if isinstance(expected_status, str) and expected_status.isdigit(): + expected_status = int(expected_status) + session = self._cache.switch(alias) method_func = getattr(session, method.lower()) diff --git a/src/HttpxLibrary/SessionKeywords.py b/src/HttpxLibrary/SessionKeywords.py index 2ed6bad..fb84e40 100644 --- a/src/HttpxLibrary/SessionKeywords.py +++ b/src/HttpxLibrary/SessionKeywords.py @@ -773,10 +773,11 @@ def _get_url(session, uri): """ Helper method to get the full url """ - url = session.url + url = str(session.url) # Ensure url is string if uri: + uri = str(uri) # Ensure uri is string slash = '' if uri.startswith('/') else '/' - url = "%s%s%s" % (session.url, slash, uri) + url = "%s%s%s" % (url, slash, uri) return url # FIXME might be broken we need a test for this