bito-code-review[bot] commented on code in PR #40277:
URL: https://github.com/apache/superset/pull/40277#discussion_r3432645307
##########
tests/integration_tests/conftest.py:
##########
@@ -213,12 +214,12 @@ def setup_presto_if_needed():
database = get_example_database()
with database.get_sqla_engine() as engine:
drop_from_schema(engine, CTAS_SCHEMA_NAME)
- engine.execute(f"DROP SCHEMA IF EXISTS {CTAS_SCHEMA_NAME}")
- engine.execute(f"CREATE SCHEMA {CTAS_SCHEMA_NAME}")
+ engine.execute(text(f"DROP SCHEMA IF EXISTS {CTAS_SCHEMA_NAME}"))
+ engine.execute(text(f"CREATE SCHEMA {CTAS_SCHEMA_NAME}"))
drop_from_schema(engine, ADMIN_SCHEMA_NAME)
- engine.execute(f"DROP SCHEMA IF EXISTS {ADMIN_SCHEMA_NAME}")
- engine.execute(f"CREATE SCHEMA {ADMIN_SCHEMA_NAME}")
+ engine.execute(text(f"DROP SCHEMA IF EXISTS {ADMIN_SCHEMA_NAME}"))
+ engine.execute(text(f"CREATE SCHEMA {ADMIN_SCHEMA_NAME}"))
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Duplicate with_feature_flags decorator</b></div>
<div id="fix">
The `with_feature_flags` decorator implementation is duplicated across
integration and unit test conftest files. Consider centralizing this utility in
a shared location to maintain a single source of truth for feature flag mocking
behavior.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
@@ -1,38 +1,8 @@
-# Duplicated decorator in tests/integration_tests/conftest.py (lines
222-257)
-# and tests/unit_tests/conftest.py (lines 182-217)
-
-def with_feature_flags(**mock_feature_flags):
- """
- Use this decorator to mock feature flags in tests.integration_tests.
-
- Usage:
-
- class TestYourFeature(SupersetTestCase):
-
- @with_feature_flags(YOUR_FEATURE=True)
- def test_your_feature_enabled(self):
- self.assertEqual(is_feature_enabled("YOUR_FEATURE"), True)
-
- @with_feature_flags(YOUR_FEATURE=False)
- def test_your_feature_disabled(self):
- self.assertEqual(is_feature_enabled("YOUR_FEATURE"), False)
- """
-
- def mock_get_feature_flags():
- feature_flags = feature_flag_manager._feature_flags or {}
- return {**feature_flags, **mock_feature_flags}
-
- def decorate(test_fn):
- def wrapper(*args, **kwargs):
- with patch.object(
- feature_flag_manager,
- "get_feature_flags",
- side_effect=mock_get_feature_flags,
- ):
- test_fn(*args, **kwargs)
-
- return functools.update_wrapper(wrapper, test_fn)
-
- return decorate
+from tests.shared.feature_flag_helpers import with_feature_flags
+
+__all__ = [
+ "with_feature_flags",
+ # ... other exports
+]
```
</div>
</details>
</div>
<div><details><summary><b>Review Rule</b></summary><div>Bito created the
rule <strong><code>Extract duplicated test utilities into shared
modules</code></strong> for <strong>repo:</strong>
<code>apache/superset</code>, <strong>language:</strong> <code>Python</code>.
Bito will avoid suggestions that match this rule. You can manage review rules
<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>here</a>.</div></details></div>
<small><i>Code Review Run #d38cb5</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]