-
Notifications
You must be signed in to change notification settings - Fork 14.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: convert dataframe tests #17655
Conversation
Codecov Report
@@ Coverage Diff @@
## master #17655 +/- ##
==========================================
+ Coverage 68.66% 68.92% +0.25%
==========================================
Files 1596 1597 +1
Lines 65224 65284 +60
Branches 6950 6950
==========================================
+ Hits 44789 44999 +210
+ Misses 18550 18400 -150
Partials 1885 1885
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
||
|
||
def test_js_max_int(app_context: None) -> None: | ||
from superset.db_engine_specs import BaseEngineSpec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why these aren't at the top of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, these imports need to be done inside an app_context
, otherwise they fail:
>>> from superset.db_engine_specs import BaseEngineSpec
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/beto/Projects/incubator-superset/superset/db_engine_specs/__init__.py", line 43, in <module>
from superset.db_engine_specs.base import BaseEngineSpec
File "/Users/beto/Projects/incubator-superset/superset/db_engine_specs/base.py", line 61, in <module>
from superset.models.sql_lab import Query
File "/Users/beto/Projects/incubator-superset/superset/models/__init__.py", line 17, in <module>
from . import (
File "/Users/beto/Projects/incubator-superset/superset/models/alerts.py", line 53, in <module>
class Alert(Model, AuditMixinNullable):
File "/Users/beto/Projects/incubator-superset/superset/models/alerts.py", line 66, in Alert
owners = relationship(security_manager.user_model, secondary=alert_owner)
File "/Users/beto/.pyenv/versions/superset/lib/python3.8/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'NoneType' object has no attribute 'user_model'
>>>
The app_context
fixture will do the initialization needed for the import. This way, it works when ran inside the test, but fails as a top-level import.
Note that this is a consequence of bad architecture in Superset. You can see that when we import BaseEngineSpec
it assumes that a user model is defined in the security manager, and it fails.
from superset.typing import DbapiDescription | ||
|
||
|
||
def test_df_to_records(app_context: None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_df_to_records(app_context: None) -> None: | |
def test_df_to_records(_: None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need app_context
here to be named as is, since it's a fixture used by the test.
] | ||
|
||
|
||
def test_js_max_int(app_context: None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_js_max_int(app_context: None) -> None: | |
def test_js_max_int(_: None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. It's a weird behavior of pytest, but we specify which fixtures we want based on their names.
SUMMARY
This converts the dataframe tests to unit tests. They're not pure unit tests, since some of the imports have side-effects that require mocking
SQLALCHEMY_DATABASE_URI
, but they run in a few seconds.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION