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 4df2139 Speed up tests/api/ from 20s down to 6s (#14833)
4df2139 is described below
commit 4df2139f62a64e17b842b07c8a6abcc095a60c28
Author: Ash Berlin-Taylor <[email protected]>
AuthorDate: Tue Mar 16 13:00:43 2021 +0000
Speed up tests/api/ from 20s down to 6s (#14833)
Not a big over-all speed up, but also not a big change
---
pylintrc-tests | 2 +-
tests/api/auth/backend/test_basic_auth.py | 26 +++++----------
tests/api/common/experimental/test_mark_tasks.py | 18 +++-------
tests/api/conftest.py | 42 ++++++++++++++++++++++++
4 files changed, 56 insertions(+), 32 deletions(-)
diff --git a/pylintrc-tests b/pylintrc-tests
index 1f72e54..541bac1 100644
--- a/pylintrc-tests
+++ b/pylintrc-tests
@@ -389,7 +389,7 @@ min-similarity-lines=4
# Regular expression matching correct argument names. Overrides argument-
# naming-style.
# BasPH: Kept snake_case but allow for 1-char argument names.
-argument-rgx=[a-z_][a-z0-9_]{0,30}$
+argument-rgx=[a-z_][a-z0-9_]{0,32}$
# Naming style matching correct attribute names.
attr-naming-style=snake_case
diff --git a/tests/api/auth/backend/test_basic_auth.py
b/tests/api/auth/backend/test_basic_auth.py
index d88bf54..49d7d30 100644
--- a/tests/api/auth/backend/test_basic_auth.py
+++ b/tests/api/auth/backend/test_basic_auth.py
@@ -15,33 +15,25 @@
# specific language governing permissions and limitations
# under the License.
-import unittest
from base64 import b64encode
+import pytest
from flask_login import current_user
from parameterized import parameterized
-from airflow.www.app import create_app
-from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_pools
-class TestBasicAuth(unittest.TestCase):
- @classmethod
- def setUpClass(cls) -> None:
- with conf_vars(
- {
- ("api", "auth_backend"): "airflow.api.auth.backend.basic_auth",
- ('api', 'enable_experimental_api'): 'true',
- }
- ):
- cls.app = create_app(testing=True)
+class TestBasicAuth:
+ @pytest.fixture(autouse=True)
+ def set_attrs(self, minimal_app_for_experimental_api):
+ self.app = minimal_app_for_experimental_api
- cls.appbuilder = cls.app.appbuilder # pylint: disable=no-member
- role_admin = cls.appbuilder.sm.find_role("Admin")
- tester = cls.appbuilder.sm.find_user(username="test")
+ self.appbuilder = self.app.appbuilder # pylint: disable=no-member
+ role_admin = self.appbuilder.sm.find_role("Admin")
+ tester = self.appbuilder.sm.find_user(username="test")
if not tester:
- cls.appbuilder.sm.add_user(
+ self.appbuilder.sm.add_user(
username="test",
first_name="test",
last_name="test",
diff --git a/tests/api/common/experimental/test_mark_tasks.py
b/tests/api/common/experimental/test_mark_tasks.py
index 5d2e754..82df7c5 100644
--- a/tests/api/common/experimental/test_mark_tasks.py
+++ b/tests/api/common/experimental/test_mark_tasks.py
@@ -16,7 +16,6 @@
# specific language governing permissions and limitations
# under the License.
-import time
import unittest
from datetime import timedelta
@@ -45,14 +44,10 @@ class TestMarkTasks(unittest.TestCase):
@classmethod
def setUpClass(cls):
models.DagBag(include_examples=True,
read_dags_from_db=False).sync_to_db()
- dagbag = models.DagBag(include_examples=True, read_dags_from_db=True)
- dagbag.collect_dags_from_db()
- cls.dag1 = dagbag.dags['miscellaneous_test_dag']
- cls.dag1.sync_to_db()
- cls.dag2 = dagbag.dags['example_subdag_operator']
- cls.dag2.sync_to_db()
- cls.dag3 = dagbag.dags['example_trigger_target_dag']
- cls.dag3.sync_to_db()
+ dagbag = models.DagBag(include_examples=False, read_dags_from_db=True)
+ cls.dag1 = dagbag.get_dag('miscellaneous_test_dag')
+ cls.dag2 = dagbag.get_dag('example_subdag_operator')
+ cls.dag3 = dagbag.get_dag('example_trigger_target_dag')
cls.execution_dates = [days_ago(2), days_ago(1)]
start_date3 = cls.dag3.start_date
cls.dag3_execution_dates = [
@@ -68,7 +63,6 @@ class TestMarkTasks(unittest.TestCase):
)
for dr in drs:
dr.dag = self.dag1
- dr.verify_integrity()
drs = _create_dagruns(
self.dag2, [self.dag2.start_date], state=State.RUNNING,
run_type=DagRunType.SCHEDULED
@@ -76,14 +70,12 @@ class TestMarkTasks(unittest.TestCase):
for dr in drs:
dr.dag = self.dag2
- dr.verify_integrity()
drs = _create_dagruns(
self.dag3, self.dag3_execution_dates, state=State.SUCCESS,
run_type=DagRunType.MANUAL
)
for dr in drs:
dr.dag = self.dag3
- dr.verify_integrity()
def tearDown(self):
clear_db_runs()
@@ -568,8 +560,6 @@ class TestMarkDAGRun(unittest.TestCase):
middle_time = timezone.utcnow()
self._set_default_task_instance_states(dr)
- time.sleep(2)
-
altered = set_dag_run_state_to_running(self.dag1, date, commit=True)
# None of the tasks should be altered, since we've only altered the
DAG itself
diff --git a/tests/api/conftest.py b/tests/api/conftest.py
new file mode 100644
index 0000000..ce06cb3
--- /dev/null
+++ b/tests/api/conftest.py
@@ -0,0 +1,42 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+
+from airflow.www import app
+from tests.test_utils.config import conf_vars
+from tests.test_utils.decorators import dont_initialize_flask_app_submodules
+
+
[email protected](scope="session")
+def minimal_app_for_experimental_api():
+ with conf_vars(
+ {
+ ("api", "auth_backend"): "airflow.api.auth.backend.basic_auth",
+ ('api', 'enable_experimental_api'): 'true',
+ }
+ ):
+
+ @dont_initialize_flask_app_submodules(
+ skip_all_except=["init_appbuilder", "init_api_experimental",
"init_api_experimental_auth"]
+ )
+ def factory():
+ # Make sure we don't issue a warning in the test summary about
deprecation
+ with pytest.deprecated_call():
+ return app.create_app(testing=True) # type:ignore
+
+ yield factory()