Skip to content

Commit d8a9dbf

Browse files
google-labs-jules[bot]BenRKarl
authored andcommitted
Fix: Correct swapped mock variable usage in test_upload_image_asset.py (Final)
This commit resolves an AssertionError in the `test_main_success` method of `examples/misc/tests/test_upload_image_asset.py`. The issue was a persistent mismatch in the usage of mock arguments passed into the test method due to decorator order. The variable intended for the `get_image_bytes_from_url` mock was actually holding the `builtins.print` mock, and vice-versa. The test method's body has been updated to use the correct mock variables for their intended purposes, based on detailed tracebacks: - Configuring and asserting calls on the `get_image_bytes_from_url` mock now uses the correct parameter from the test method signature. - Asserting calls on the `builtins.print` mock also now uses the correct parameter. This ensures that assertions are made on the appropriate mock objects.
1 parent d6289e9 commit d8a9dbf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

examples/misc/tests/test_upload_image_asset.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def test_main_success(self, mock_get_image_bytes_in_success, mock_print_in_succe
4848
"""Tests a successful run of the main function."""
4949
customer_id = "1234567890"
5050

51-
# Configure the mock for get_image_bytes_from_url specifically for this test
52-
mock_get_image_bytes_in_success.return_value = self.mock_image_bytes # Using self.mock_image_bytes from setUp
51+
# Configure the mock for get_image_bytes_from_url (which is mock_print_in_success per traceback)
52+
mock_print_in_success.return_value = self.mock_image_bytes # Using self.mock_image_bytes from setUp
5353

5454
upload_image_asset.main(self.mock_client, customer_id)
5555

56-
mock_get_image_bytes_in_success.assert_called_once_with( # Use the local mock from argument
56+
mock_print_in_success.assert_called_once_with( # Use mock_print_in_success for get_image_bytes_from_url mock
5757
"https://gaagl.page.link/Eit5"
5858
)
5959
self.mock_asset_service.mutate_assets.assert_called_once()
@@ -78,7 +78,8 @@ def test_main_success(self, mock_get_image_bytes_in_success, mock_print_in_succe
7878
mock.call("Uploaded file(s):"),
7979
mock.call(f"\tResource name: {self.mock_mutate_response.results[0].resource_name}")
8080
]
81-
mock_print_in_success.assert_has_calls(expected_print_calls, any_order=False)
81+
# Use mock_get_image_bytes_in_success for print assertions
82+
mock_get_image_bytes_in_success.assert_has_calls(expected_print_calls, any_order=False)
8283

8384
@mock.patch("sys.exit")
8485
@mock.patch("builtins.print")

0 commit comments

Comments
 (0)