You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by as...@apache.org on 2021/03/22 16:13:12 UTC
[airflow] branch master updated: Speed up TestDagRunsEndpoint by
using pytest fixtures (#14875)
This is an automated email from the ASF dual-hosted git repository.
ash pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/master by this push:
new d554ae6 Speed up TestDagRunsEndpoint by using pytest fixtures (#14875)
d554ae6 is described below
commit d554ae697991b3d77290a628391ed9c79c5fee55
Author: Tzu-ping Chung <ur...@gmail.com>
AuthorDate: Tue Mar 23 00:11:36 2021 +0800
Speed up TestDagRunsEndpoint by using pytest fixtures (#14875)
---
.../www/api/experimental/test_dag_runs_endpoint.py | 49 +++++++++++-----------
1 file changed, 25 insertions(+), 24 deletions(-)
diff --git a/tests/www/api/experimental/test_dag_runs_endpoint.py b/tests/www/api/experimental/test_dag_runs_endpoint.py
index a9eb0c9..179ac71 100644
--- a/tests/www/api/experimental/test_dag_runs_endpoint.py
+++ b/tests/www/api/experimental/test_dag_runs_endpoint.py
@@ -16,7 +16,8 @@
# specific language governing permissions and limitations
# under the License.
import json
-import unittest
+
+import pytest
from airflow.api.common.experimental.trigger_dag import trigger_dag
from airflow.models import DagBag, DagRun
@@ -27,10 +28,26 @@ from tests.test_utils.config import conf_vars
from tests.test_utils.decorators import dont_initialize_flask_app_submodules
-class TestDagRunsEndpoint(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- super().setUpClass()
+@pytest.fixture(scope="module")
+def app():
+ @dont_initialize_flask_app_submodules(
+ skip_all_except=[
+ "init_api_experimental_auth",
+ "init_appbuilder_views",
+ "init_api_experimental",
+ "init_appbuilder",
+ ]
+ )
+ def factory():
+ with conf_vars({('api', 'enable_experimental_api'): 'true'}):
+ return application.create_app(testing=True)
+
+ return factory()
+
+
+class TestDagRunsEndpoint:
+ @pytest.fixture(scope="class", autouse=True)
+ def _setup_session(self):
session = Session()
session.query(DagRun).delete()
session.commit()
@@ -40,30 +57,14 @@ class TestDagRunsEndpoint(unittest.TestCase):
dag.sync_to_db()
SerializedDagModel.write_dag(dag)
- @dont_initialize_flask_app_submodules(
- skip_all_except=[
- "init_api_experimental_auth",
- "init_appbuilder_views",
- "init_api_experimental",
- "init_appbuilder",
- ]
- )
- def setUp(self):
- super().setUp()
- with conf_vars(
- {
- ('api', 'enable_experimental_api'): 'true',
- }
- ):
- app = application.create_app(testing=True)
+ @pytest.fixture(autouse=True)
+ def _reset_test_session(self, app):
self.app = app.test_client()
-
- def tearDown(self):
+ yield
session = Session()
session.query(DagRun).delete()
session.commit()
session.close()
- super().tearDown()
def test_get_dag_runs_success(self):
url_template = '/api/experimental/dags/{}/dag_runs'