You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/03/17 22:08:44 UTC

[GitHub] [airflow] uranusjr opened a new pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

uranusjr opened a new pull request #14863:
URL: https://github.com/apache/airflow/pull/14863


   A follow-up to #14746, this applies a similar approach to convert tests to use Pytest fixtures.
   
   I managed to make all but one test to work. The one failure (marked as xfail for now) is `TestAirflowBaseViews::test_index`; somehow my conversion makes the index page to only use 8 queries instead of the previous 43. I couldn’t figure out what caused the change and would be happy for any insights.
   
   The change does not produce any measuable time difference from my benchmarks, which is kind of expected since I mostly performed one-to-one conversion from `setUpClass` to `scope="class"` and `setUp` to `scope="function"`. I intend to go through the changes and try to locate any possible optimisations, but it seems the tests did not re-create expensive resources repeated to begin with.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
uranusjr commented on pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#issuecomment-809665039


   This is probably not going to work? Are there benefits converting tests to use pytest fixtures without the performance gain?


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
uranusjr commented on pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#issuecomment-826039117


   I don’t think this is worthwhile (unless we *really* want to convert the module to pytest fixtures dispite there’s no performance gain available)


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr closed pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
uranusjr closed pull request #14863:
URL: https://github.com/apache/airflow/pull/14863


   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#issuecomment-801509444


   [The Workflow run](https://github.com/apache/airflow/actions/runs/662776699) is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#discussion_r596760905



##########
File path: tests/www/test_views.py
##########
@@ -122,31 +122,39 @@ def local_context(self):
         return result
 
 
-class TestBase(unittest.TestCase):
-    @classmethod
-    @dont_initialize_flask_app_submodules(
-        skip_all_except=[
-            "init_appbuilder",
-            "init_appbuilder_views",
-            "init_flash_views",
-            "init_jinja_globals",
-        ]
-    )
-    def setUpClass(cls):
+class TestBase:
+    @pytest.fixture(scope="class")

Review comment:
       But can we? `minimal_app` is mutated in a lot of test preparations, and making the fixture module-scoped would make those side effects leak out to other tests. For example, I don’t think `init_api_connexion` can be called multiple times on the same app. `TestAirflowBaseViews` also sets `app.dag_bag` which would affect subsequent tests using the same app.
   
   I agree with moving it to `conftest.py` though. I’m keeping things as local as possible for now, and will move it when I start working on other files in `tests/www`.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#discussion_r596802445



##########
File path: tests/www/test_views.py
##########
@@ -122,31 +122,39 @@ def local_context(self):
         return result
 
 
-class TestBase(unittest.TestCase):
-    @classmethod
-    @dont_initialize_flask_app_submodules(
-        skip_all_except=[
-            "init_appbuilder",
-            "init_appbuilder_views",
-            "init_flash_views",
-            "init_jinja_globals",
-        ]
-    )
-    def setUpClass(cls):
+class TestBase:
+    @pytest.fixture(scope="class")

Review comment:
       I tried making `minimal_app` module-scope and `TestDagRunModelView::test_clear_dag_runs_action` fails. And interestingly, it also does not speed up the tests 🤔 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr edited a comment on pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
uranusjr edited a comment on pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#issuecomment-826039117


   I don’t think this is worthwhile (unless we *really* want to convert the module to pytest fixtures despite there’s no performance gain available)


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#discussion_r596428652



##########
File path: tests/www/test_views.py
##########
@@ -122,31 +122,39 @@ def local_context(self):
         return result
 
 
-class TestBase(unittest.TestCase):
-    @classmethod
-    @dont_initialize_flask_app_submodules(
-        skip_all_except=[
-            "init_appbuilder",
-            "init_appbuilder_views",
-            "init_flash_views",
-            "init_jinja_globals",
-        ]
-    )
-    def setUpClass(cls):
+class TestBase:
+    @pytest.fixture(scope="class")

Review comment:
       Making this session scoped will I think make a big difference.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#discussion_r596430659



##########
File path: tests/www/test_views.py
##########
@@ -122,31 +122,39 @@ def local_context(self):
         return result
 
 
-class TestBase(unittest.TestCase):
-    @classmethod
-    @dont_initialize_flask_app_submodules(
-        skip_all_except=[
-            "init_appbuilder",
-            "init_appbuilder_views",
-            "init_flash_views",
-            "init_jinja_globals",
-        ]
-    )
-    def setUpClass(cls):
+class TestBase:
+    @pytest.fixture(scope="class")

Review comment:
       And if you make this a fixture in `tests/www/conftest.py` then it can be used by `tests/www/test_app.py` etc too (I have a change where I'd like to use this in, for instance.)




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] boring-cyborg[bot] commented on pull request #14863: Convert tests/www/test_views.py to use Pytest fixtures

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #14863:
URL: https://github.com/apache/airflow/pull/14863#issuecomment-801474406


   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (flake8, pylint and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/master/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/master/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/master/BREEZE.rst) for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#coding-style-and-best-practices).
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org