codeant-ai-for-open-source[bot] commented on code in PR #41133: URL: https://github.com/apache/superset/pull/41133#discussion_r3574622446
########## tests/unit_tests/utils/s3_tests.py: ########## @@ -0,0 +1,95 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import sys +from unittest.mock import MagicMock, patch + +import pytest + +from superset.utils import s3 + + +@patch("boto3.client") Review Comment: **Suggestion:** Patching `boto3.client` directly makes this test module require the optional `boto3` package at import/collection time, which will fail in environments that intentionally run without the `excel-export` extra. Patch `superset.utils.s3._get_s3_client` (or inject a fake `boto3` module via `patch.dict(sys.modules, ...)`) instead so these unit tests validate S3 helper behavior without hard-depending on an optional dependency. [import error] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ❌ S3 helper unit tests fail when boto3 not installed. - ⚠️ Test suite cannot run in minimal excel-export-less environments. ``` </details> <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Create a Python environment with the Superset repo checked out but without installing the optional excel-export extra, so the boto3 package is absent. 2. Run pytest against tests/unit_tests/utils/s3_tests.py, causing pytest to import this module for test collection. 3. During import, the decorators @patch("boto3.client") at lines 27, 41, and 81 in tests/unit_tests/utils/s3_tests.py are evaluated, and unittest.mock.patch attempts importlib.import_module("boto3"). 4. Because boto3 is not installed or present in sys.modules, importlib.import_module raises ModuleNotFoundError, and test collection fails before any tests (including the lazy-import behavior in superset/utils/s3.py:36-48) can run. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1f48824020514a539daf62ad6c2480c7&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=1f48824020514a539daf62ad6c2480c7&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/utils/s3_tests.py **Line:** 27:27 **Comment:** *Import Error: Patching `boto3.client` directly makes this test module require the optional `boto3` package at import/collection time, which will fail in environments that intentionally run without the `excel-export` extra. Patch `superset.utils.s3._get_s3_client` (or inject a fake `boto3` module via `patch.dict(sys.modules, ...)`) instead so these unit tests validate S3 helper behavior without hard-depending on an optional dependency. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=cfb9a6a44d09118b772beb4d94b4390707e91c0f9f33125b0cb6e0601d018c91&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=cfb9a6a44d09118b772beb4d94b4390707e91c0f9f33125b0cb6e0601d018c91&reaction=dislike'>👎</a> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
