ashb commented on a change in pull request #15141:
URL: https://github.com/apache/airflow/pull/15141#discussion_r612378895



##########
File path: tests/api/auth/backend/test_kerberos_auth.py
##########
@@ -19,42 +19,46 @@
 import json
 import os
 import socket
-import unittest
 from datetime import datetime
 from unittest import mock
 
 import pytest
 
 from airflow.api.auth.backend.kerberos_auth import CLIENT_AUTH
 from airflow.models import DagBag
-from airflow.www import app as application
+from airflow.www import app
 from tests.test_utils.config import conf_vars
 from tests.test_utils.db import clear_db_dags
 
 KRB5_KTNAME = os.environ.get("KRB5_KTNAME")
 
 
[email protected]("kerberos")
-class TestApiKerberos(unittest.TestCase):
-    @classmethod
-    def setUpClass(cls):
-        dagbag = DagBag(include_examples=True)
-        for dag in dagbag.dags.values():
-            dag.sync_to_db()
-
-    @conf_vars(
[email protected](scope="module")
+def app_for_kerberos():
+    with conf_vars(
         {
             ("api", "auth_backend"): "airflow.api.auth.backend.kerberos_auth",
             ("kerberos", "keytab"): KRB5_KTNAME,
             ('api', 'enable_experimental_api'): 'true',
         }
-    )
-    def setUp(self):
-        self.app = application.create_app(testing=True)
+    ):
+        yield app.create_app(testing=True)
+
+
[email protected](scope="module", autouse=True)
+def dagbag_to_db():
+    dagbag = DagBag(include_examples=True)
+    for dag in dagbag.dags.values():
+        dag.sync_to_db()
+    yield
+    clear_db_dags()
 
-    @classmethod
-    def tearDownClass(cls) -> None:
-        clear_db_dags()
+
[email protected]("kerberos")
+class TestApiKerberos:
+    @pytest.fixture(autouse=True)
+    def _set_attrs(self, app_for_kerberos):

Review comment:
       Again here, because of `autouse=True` the name doesn't matter -- pytest 
will ensure that it is called before each test function.

##########
File path: tests/api/auth/backend/test_kerberos_auth.py
##########
@@ -19,42 +19,46 @@
 import json
 import os
 import socket
-import unittest
 from datetime import datetime
 from unittest import mock
 
 import pytest
 
 from airflow.api.auth.backend.kerberos_auth import CLIENT_AUTH
 from airflow.models import DagBag
-from airflow.www import app as application
+from airflow.www import app
 from tests.test_utils.config import conf_vars
 from tests.test_utils.db import clear_db_dags
 
 KRB5_KTNAME = os.environ.get("KRB5_KTNAME")
 
 
[email protected]("kerberos")
-class TestApiKerberos(unittest.TestCase):
-    @classmethod
-    def setUpClass(cls):
-        dagbag = DagBag(include_examples=True)
-        for dag in dagbag.dags.values():
-            dag.sync_to_db()
-
-    @conf_vars(
[email protected](scope="module")
+def app_for_kerberos():
+    with conf_vars(
         {
             ("api", "auth_backend"): "airflow.api.auth.backend.kerberos_auth",
             ("kerberos", "keytab"): KRB5_KTNAME,
             ('api', 'enable_experimental_api'): 'true',
         }
-    )
-    def setUp(self):
-        self.app = application.create_app(testing=True)
+    ):
+        yield app.create_app(testing=True)
+
+
[email protected](scope="module", autouse=True)
+def dagbag_to_db():

Review comment:
       `autouse=True` means PyTest will automatically make sure that this 
function is called once per module




-- 
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:
[email protected]


Reply via email to