codeant-ai-for-open-source[bot] commented on code in PR #38890:
URL: https://github.com/apache/superset/pull/38890#discussion_r3002674970


##########
tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py:
##########
@@ -59,7 +59,7 @@ def mock_auth():
         yield mock_get_user
 
 
[email protected](autouse=True)
[email protected]()(autouse=True)

Review Comment:
   **Suggestion:** The autouse fixtures are decorated with 
`@pytest.fixture()(autouse=True)`, which incorrectly calls the fixture 
decorator's result with an unexpected `autouse` keyword argument; this will 
raise a TypeError at import time and prevent the fixtures from being 
registered, breaking all tests that rely on mocked auth and chart access. 
Change the decorators to `@pytest.fixture(autouse=True)` so that `autouse` is 
passed as a parameter to the fixture decorator itself instead of to the 
returned marker. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ test_dashboard_generation module fails to import under pytest.
   - ⚠️ generate_dashboard MCP tool behavior left untested.
   - ⚠️ add_chart_to_existing_dashboard layout logic unverified.
   - ⚠️ Tabbed dashboard layout helper behavior lacks regression coverage.
   ```
   </details>
   
   ```suggestion
   @pytest.fixture(autouse=True)
   def mock_auth():
       """Mock authentication for all tests."""
       with patch("superset.mcp_service.auth.get_user_from_request") as 
mock_get_user:
           mock_user = Mock()
           mock_user.id = 1
           mock_user.username = "admin"
           mock_get_user.return_value = mock_user
           yield mock_get_user
   
   
   @pytest.fixture(autouse=True)
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Run the test module
   `tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py` 
with pytest
   (e.g., `pytest 
tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py`),
   which causes Python to import this file.
   
   2. During import, Python executes the decorator on line 51
   (`@pytest.fixture()(autouse=True)` in `test_dashboard_generation.py:51`), 
which first
   calls `pytest.fixture()` and returns a `FixtureFunctionMarker` instance.
   
   3. Python then attempts to call this `FixtureFunctionMarker` with the 
keyword argument
   `autouse=True` before applying it to `mock_auth`; this invokes
   `FixtureFunctionMarker.__call__` with an unexpected keyword argument, 
raising `TypeError:
   __call__() got an unexpected keyword argument 'autouse'` and aborting the 
module import.
   
   4. Because the module fails to import, all tests in `TestGenerateDashboard`,
   `TestAddChartToExistingDashboard`, `TestLayoutHelpers`, 
`TestGenerateTitleFromCharts`, and
   `TestDashboardSerializationEagerLoading` defined in
   `tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py` 
are not
   collected or executed, and the intended autouse fixtures `mock_auth` and
   `mock_chart_access` are never registered.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
   **Line:** 51:62
   **Comment:**
        *Type Error: The autouse fixtures are decorated with 
`@pytest.fixture()(autouse=True)`, which incorrectly calls the fixture 
decorator's result with an unexpected `autouse` keyword argument; this will 
raise a TypeError at import time and prevent the fixtures from being 
registered, breaking all tests that rely on mocked auth and chart access. 
Change the decorators to `@pytest.fixture(autouse=True)` so that `autouse` is 
passed as a parameter to the fixture decorator itself instead of to the 
returned marker.
   
   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.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38890&comment_hash=72128956f9c022755d1ef1ef7648dfd632df79c0f307cdab354ae6c63078dfdb&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38890&comment_hash=72128956f9c022755d1ef1ef7648dfd632df79c0f307cdab354ae6c63078dfdb&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]

Reply via email to