Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down
8 changes: 3 additions & 5 deletions src/pytest_ibutsu/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
47 changes: 21 additions & 26 deletions tests/test_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -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
Comment thread
mshriver marked this conversation as resolved.
assert sender._captured_data_content() == "None"

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading