From 5b57ae3207c69ab9c6028f8bb966fc1b0aaef40f Mon Sep 17 00:00:00 2001 From: Chidambaranathan Date: Tue, 8 Jul 2025 05:30:38 +0000 Subject: [PATCH 1/2] fix: resolve test failures in retry mechanisms - Fix list comparison in retry configuration tests using List Should Contain Value - Add proper type conversion for Robot Framework parameters (str to int/float) - Fix _get_url method to handle string conversion properly - Create copy of retry config to avoid modifying original configuration - Handle boolean parameter conversion from Robot Framework strings These fixes address: - TypeError: can only concatenate str (not int) to str - List comparison issues in configuration tests - Parameter type mismatches from Robot Framework --- atests/test_retry_mechanisms.robot | 6 ++--- src/HttpxLibrary/RetryKeywords.py | 35 +++++++++++++++++++++++++---- src/HttpxLibrary/SessionKeywords.py | 5 +++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/atests/test_retry_mechanisms.robot b/atests/test_retry_mechanisms.robot index 342c8c7..c0928b5 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 From 3b69bf0114dc76e2dceb8af93ebd436be71bc86e Mon Sep 17 00:00:00 2001 From: Chidambaranathan Date: Tue, 8 Jul 2025 06:17:19 +0000 Subject: [PATCH 2/2] fix: use integer variables in retry configuration test Change from string literals (500) to integer variables () in List Should Contain Value assertions to match the integer values returned by the retry configuration. --- atests/test_retry_mechanisms.robot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atests/test_retry_mechanisms.robot b/atests/test_retry_mechanisms.robot index c0928b5..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 - 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 + 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