Skip to content

Commit 761a650

Browse files
committed
Move coverage for get_artifact failure to dedicated unit test
Previously, the test_get_artifact unit test was configured to provide coverage for the normal operation of the get_artifact function as well as its behavior when unable to download the workflow artifact. The code used to test the normal operation was almost completely unnecessary for testing the failure condition and the code for adjusting the test behavior depending on which conditions were intended to be covered added significant complexity. Since the failure is expected to occur under normal operating conditions due to transient network outages, it is worth continuing to provide coverage for this. So the chosen approach to providing coverage without negatively impacting the test code is to move it to a dedicated test.
1 parent c438d0b commit 761a650

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

reportsizedeltas/tests/test_reportsizedeltas.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,7 @@ def test_get_artifact_data_for_run(expired, artifact_name):
460460
)
461461

462462

463-
@pytest.mark.parametrize(
464-
"test_artifact_name, expected_success", [("correct-artifact-name", True), ("incorrect-artifact-name", False)]
465-
)
466-
def test_get_artifact(tmp_path, test_artifact_name, expected_success):
463+
def test_get_artifact_success(tmp_path):
467464
artifact_source_path = test_data_path.joinpath("size-deltas-reports-new")
468465

469466
# Create temporary folder
@@ -473,7 +470,7 @@ def test_get_artifact(tmp_path, test_artifact_name, expected_success):
473470
artifact_archive_destination_path = artifact_destination_path.joinpath(real_artifact_name + ".zip")
474471

475472
artifact_data = {
476-
"archive_download_url": artifact_destination_path.joinpath(test_artifact_name + ".zip").as_uri(),
473+
"archive_download_url": artifact_destination_path.joinpath(real_artifact_name + ".zip").as_uri(),
477474
"name": "artifact_name",
478475
}
479476

@@ -484,15 +481,23 @@ def test_get_artifact(tmp_path, test_artifact_name, expected_success):
484481

485482
report_size_deltas = get_reportsizedeltas_object()
486483

487-
if expected_success:
488-
artifact_folder_object = report_size_deltas.get_artifact(artifact_data=artifact_data)
484+
artifact_folder_object = report_size_deltas.get_artifact(artifact_data=artifact_data)
489485

490-
with artifact_folder_object as artifact_folder:
491-
# Verify that the artifact matches the source
492-
assert directories_are_same(left_directory=artifact_source_path, right_directory=artifact_folder)
493-
else:
494-
with pytest.raises(expected_exception=urllib.error.URLError):
495-
report_size_deltas.get_artifact(artifact_data=artifact_data)
486+
with artifact_folder_object as artifact_folder:
487+
# Verify that the artifact matches the source
488+
assert directories_are_same(left_directory=artifact_source_path, right_directory=artifact_folder)
489+
490+
491+
def test_get_artifact_failure():
492+
artifact_data = {
493+
"archive_download_url": "http://httpstat.us/404",
494+
"name": "artifact_name",
495+
}
496+
497+
report_size_deltas = get_reportsizedeltas_object()
498+
499+
with pytest.raises(expected_exception=urllib.error.URLError):
500+
report_size_deltas.get_artifact(artifact_data=artifact_data)
496501

497502

498503
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)