Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add test to check for import errors for all DAGs in the dags dir (#580)

Staci Cooperea1016deac86
diff --git a/tests/dags/test_dag_parsing.py b/tests/dags/test_dag_parsing.py
index a737e24b7..ad148209b 100644
--- a/tests/dags/test_dag_parsing.py
+++ b/tests/dags/test_dag_parsing.py
@@ -39,10 +39,26 @@ EXPECTED_COUNT = {
}
+def test_dag_import_errors():
+ # Attempt to load all DAGs in the DAG_FOLDER, and detect import
+ # errors
+ dagbag = DagBag(dag_folder=DAG_FOLDER, include_examples=False)
+
+ dag_errors = []
+ for filename in dagbag.import_errors.keys():
+ dag_errors.append(Path(filename).name)
+ error_string = ",".join(dag_errors)
+
+ assert (
+ len(dagbag.import_errors) == 0
+ ), f"Errors found during DAG import for files: {error_string}"
+
+
# relative_path represents the path from the DAG folder to the file
@pytest.mark.parametrize("relative_path", DAG_PATHS)
-def test_dag_loads_with_no_errors(relative_path, tmpdir):
- # Assume only 1 DAG is expected unless otherwise provided
+def test_dags_loads_correct_number_with_no_errors(relative_path, tmpdir):
+ # For each configured DAG file, test that the expected number of DAGs
+ # is loaded. Assume only 1 DAG is expected unless otherwise provided
expected_count = EXPECTED_COUNT.get(relative_path, 1)
dag_bag = DagBag(dag_folder=tmpdir, include_examples=False)
dag_bag.process_file(str(DAG_FOLDER / relative_path))