mnojek commented on a change in pull request #22311:
URL: https://github.com/apache/airflow/pull/22311#discussion_r830825647



##########
File path: tests/always/test_example_dags.py
##########
@@ -29,33 +30,38 @@
 NO_DB_QUERY_EXCEPTION = ["/airflow/example_dags/example_subdag_operator.py"]
 
 
-class TestExampleDags(unittest.TestCase):
-    def test_should_be_importable(self):
-        example_dags = 
list(glob(f"{ROOT_FOLDER}/airflow/**/example_dags/example_*.py", 
recursive=True))
-        assert 0 != len(example_dags)
-        for filepath in example_dags:
-            relative_filepath = os.path.relpath(filepath, ROOT_FOLDER)
-            with self.subTest(f"File {relative_filepath} should contain dags"):
-                dagbag = DagBag(
-                    dag_folder=filepath,
-                    include_examples=False,
-                )
-                assert 0 == len(dagbag.import_errors), 
f"import_errors={str(dagbag.import_errors)}"
-                assert len(dagbag.dag_ids) >= 1
-
-    def test_should_not_do_database_queries(self):
-        example_dags = 
glob(f"{ROOT_FOLDER}/airflow/**/example_dags/example_*.py", recursive=True)
-        example_dags = [
-            dag_file
-            for dag_file in example_dags
-            if any(not dag_file.endswith(e) for e in NO_DB_QUERY_EXCEPTION)
-        ]
-        assert 0 != len(example_dags)
-        for filepath in example_dags:
-            relative_filepath = os.path.relpath(filepath, ROOT_FOLDER)
-            with self.subTest(f"File {relative_filepath} shouldn't do database 
queries"):
-                with assert_queries_count(0):
-                    DagBag(
-                        dag_folder=filepath,
-                        include_examples=False,
-                    )
+def example_dags():
+    example_dirs = ["airflow/**/example_dags/example_*.py", 
"tests/system/providers/**/example_*.py"]
+    for example_dir in example_dirs:
+        yield from glob(f"{ROOT_FOLDER}/{example_dir}", recursive=True)
+
+
+def example_dags_except_db_exception():
+    return [
+        dag_file
+        for dag_file in example_dags()
+        if any(not dag_file.endswith(e) for e in NO_DB_QUERY_EXCEPTION)
+    ]
+
+
+def relative_path(path):
+    return os.path.relpath(path, ROOT_FOLDER)
+
+
[email protected]("example", list(example_dags()), ids=relative_path)
+def test_should_be_importable(example):
+    dagbag = DagBag(
+        dag_folder=example,
+        include_examples=False,
+    )
+    assert 0 == len(dagbag.import_errors), 
f"import_errors={str(dagbag.import_errors)}"

Review comment:
       The code is updated




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to