From 9a0c23bdcda8ac584593d893bfed10baf5b967da Mon Sep 17 00:00:00 2001 From: mshriver Date: Mon, 20 Oct 2025 14:24:22 +0200 Subject: [PATCH 1/2] Update for kwargs on artifact upload --- pyproject.toml | 7 +++++- src/pytest_ibutsu/sender.py | 8 +++---- tests/test_sender.py | 47 +++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c217f65..dc747d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,12 @@ include = ["/src"] packages = ["/src/pytest_ibutsu"] [tool.hatch.envs.hatch-test] -extra-dependencies = ["pytest-ibutsu[test]"] +extra-dependencies = [ + "pytest-xdist", + "python-jose", + "pytest-cov", + "coverage[toml]", +] [[tool.hatch.envs.hatch-test.matrix]] python = ["3.11", "3.12", "3.13"] diff --git a/src/pytest_ibutsu/sender.py b/src/pytest_ibutsu/sender.py index 7e56845..644e51d 100644 --- a/src/pytest_ibutsu/sender.py +++ b/src/pytest_ibutsu/sender.py @@ -337,13 +337,11 @@ def _upload_artifact( logger.error("Artifact size is greater than upload limit") return - # Get prepared data using the unified handler - processed_data = handler.prepared_data - + # Pass data directly to the API self._make_call( self.artifact_api.upload_artifact, - filename, - processed_data, + filename=filename, + file=handler.prepared_data, hide_exception=False, **kwargs, ) diff --git a/tests/test_sender.py b/tests/test_sender.py index f5cefc7..1fb1633 100644 --- a/tests/test_sender.py +++ b/tests/test_sender.py @@ -27,9 +27,7 @@ def _create_data_capturing_sender(): def capture_data(*args, **kwargs): nonlocal captured_data_content - if len(args) >= 3: - data = args[2] - captured_data_content = data + captured_data_content = kwargs.get("file", captured_data_content) sender._make_call = Mock(side_effect=capture_data) sender._captured_data_content = lambda: captured_data_content @@ -42,12 +40,9 @@ def _create_multi_data_capturing_sender(): captured_calls = [] def capture_data(*args, **kwargs): - if len(args) >= 3: - data = args[2] - # Store the call with captured content - captured_calls.append( - {"args": args, "kwargs": kwargs, "data_content": data} - ) + data = kwargs.get("file") + # Store the call with captured content + captured_calls.append({"args": args, "kwargs": kwargs, "data_content": data}) sender._make_call = Mock(side_effect=capture_data) sender._captured_calls = lambda: captured_calls @@ -236,7 +231,7 @@ def test_upload_artifact_bytes_under_limit(self): # Verify it's called with artifact API and correct arguments args, kwargs = sender._make_call.call_args assert args[0] == sender.artifact_api.upload_artifact - assert args[1] == "test.txt" # filename + assert kwargs["filename"] == "test.txt" # Verify the data content was captured correctly assert sender._captured_data_content() == content # data passed directly assert kwargs["result_id"] == "result-id" @@ -251,7 +246,7 @@ def test_upload_artifact_string_content(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args assert args[0] == sender.artifact_api.upload_artifact - assert args[1] == "test.txt" + assert kwargs["filename"] == "test.txt" # Verify the data content was captured correctly - should be passed as string assert sender._captured_data_content() == content # String passed directly assert kwargs["result_id"] == "result-id" @@ -270,7 +265,7 @@ def test_upload_artifact_file_path(self, tmp_path): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args assert args[0] == sender.artifact_api.upload_artifact - assert args[1] == "test.txt" + assert kwargs["filename"] == "test.txt" # Verify the data content was captured correctly - should be file content as bytes assert ( sender._captured_data_content() == test_content.encode() @@ -293,7 +288,7 @@ def test_upload_artifact_binary_file_path(self, tmp_path): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args assert args[0] == sender.artifact_api.upload_artifact - assert args[1] == "test_image.png" + assert kwargs["filename"] == "test_image.png" # Verify the data content was captured correctly assert ( sender._captured_data_content() == binary_content @@ -314,7 +309,7 @@ def test_upload_artifact_non_utf8_file_path(self, tmp_path): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args assert args[0] == sender.artifact_api.upload_artifact - assert args[1] == "latin1_file.txt" + assert kwargs["filename"] == "latin1_file.txt" # Verify the data content was captured correctly assert sender._captured_data_content() == latin1_content.encode("latin-1") assert kwargs["result_id"] == "result-id" @@ -472,7 +467,7 @@ def test_upload_artifact_empty_string(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args assert args[0] == sender.artifact_api.upload_artifact - assert args[1] == "empty.txt" + assert kwargs["filename"] == "empty.txt" # Verify the data content was captured correctly - empty string passed as string assert sender._captured_data_content() == "" # Empty string passed directly @@ -486,7 +481,7 @@ def test_upload_artifact_data_none(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args assert args[0] == sender.artifact_api.upload_artifact - assert args[1] == "none_data.txt" + assert kwargs["filename"] == "none_data.txt" # None gets converted to "None" string assert sender._captured_data_content() == "None" @@ -513,7 +508,7 @@ def test_text_log_upload_like_iqe_core(self, tmp_path): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args assert args[0] == sender.artifact_api.upload_artifact - assert args[1] == "iqe.log" + assert kwargs["filename"] == "iqe.log" # Verify the data content was captured correctly assert sender._captured_data_content() == log_bytes # Should be the exact bytes assert kwargs["result_id"] == result.id @@ -536,7 +531,7 @@ def test_network_log_upload_like_iqe_core(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args - assert args[1] == "net.log" + assert kwargs["filename"] == "net.log" # Verify the data content was captured correctly assert sender._captured_data_content() == net_log_bytes @@ -558,7 +553,7 @@ def test_browser_log_upload_like_iqe_core(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args - assert args[1] == "browser.log" + assert kwargs["filename"] == "browser.log" # Verify the data content was captured correctly assert sender._captured_data_content() == browser_log_bytes @@ -582,7 +577,7 @@ def test_screenshot_upload_like_iqe_core(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args - assert args[1] == "screenshot.png" + assert kwargs["filename"] == "screenshot.png" # Verify the data content was captured correctly assert ( sender._captured_data_content() == mock_png_data @@ -607,7 +602,7 @@ def test_navigation_gif_upload_like_iqe_core(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args - assert args[1] == "nav.gif" + assert kwargs["filename"] == "nav.gif" # Verify the data content was captured correctly assert ( sender._captured_data_content() == mock_gif_data @@ -633,7 +628,7 @@ def test_traceback_log_upload_like_iqe_core(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args - assert args[1] == "traceback.log" + assert kwargs["filename"] == "traceback.log" # Verify the data content was captured correctly assert sender._captured_data_content() == traceback_bytes @@ -664,7 +659,7 @@ def test_multiple_artifacts_upload_like_iqe_core(self): # Check that all artifacts were uploaded with correct data captured_calls = sender._captured_calls() uploaded_files = { - call["args"][1]: call["data_content"] for call in captured_calls + call["kwargs"]["filename"]: call["data_content"] for call in captured_calls } assert "iqe.log" in uploaded_files @@ -689,7 +684,7 @@ def test_run_artifact_upload_like_iqe_core(self): sender._make_call.assert_called_once() args, kwargs = sender._make_call.call_args - assert args[1] == "run_setup.log" + assert kwargs["filename"] == "run_setup.log" # Verify the data content was captured correctly assert sender._captured_data_content() == run_log_content.encode("utf-8") assert kwargs["run_id"] == run.id @@ -719,7 +714,7 @@ def test_buffered_reader_artifact_upload(self): args, kwargs = sender._make_call.call_args # Verify the filename - assert args[1] == "test.log" + assert kwargs["filename"] == "test.log" # Verify the data content was properly converted from BufferedReader to bytes captured_data = sender._captured_data_content() @@ -754,7 +749,7 @@ def test_text_buffered_reader_artifact_upload(self): args, kwargs = sender._make_call.call_args # Verify the filename - assert args[1] == "test.log" + assert kwargs["filename"] == "test.log" # Verify the data content was properly converted from text stream to bytes captured_data = sender._captured_data_content() From b10e8a918425ace256fd78fccda24bd0c8531ec1 Mon Sep 17 00:00:00 2001 From: mshriver Date: Tue, 21 Oct 2025 15:54:27 +0200 Subject: [PATCH 2/2] Specify ibutsu-client 3.1.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index dc747d6..bd76846 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ dependencies = [ "attrs", "boto3", "cattrs", - "ibutsu-client>3", + "ibutsu-client>=3.1.1", "pytest", ] description = "A plugin to sent pytest results to an Ibutsu server"