From a8d64c93bab50d6b94242940a82f3fb759687180 Mon Sep 17 00:00:00 2001 From: Collin McNulty Date: Fri, 10 May 2024 10:13:26 -0500 Subject: [PATCH] Allow users to add dag_integrity_exceptions.txt to ignore errors (#1613) * Allow users to add dag_integrity_exceptions.txt to ignore errors * add text file to astro dev init --------- Co-authored-by: David Koenitzer --- airflow/airflow.go | 1 + airflow/include/dagintegritytestdefault.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/airflow/airflow.go b/airflow/airflow.go index b724a0224..2544c2af9 100644 --- a/airflow/airflow.go +++ b/airflow/airflow.go @@ -115,6 +115,7 @@ func Init(path, airflowImageName, airflowImageTag string) error { "README.md": Readme, "tests/dags/test_dag_example.py": DagExampleTest, ".astro/test_dag_integrity_default.py": DagIntegrityTestDefault, + ".astro/dag_integrity_exceptions.txt": "# Add dag files to exempt from parse test below. ex: dags/", } // Initailize directories diff --git a/airflow/include/dagintegritytestdefault.py b/airflow/include/dagintegritytestdefault.py index 4b9a73ed2..e433703be 100644 --- a/airflow/include/dagintegritytestdefault.py +++ b/airflow/include/dagintegritytestdefault.py @@ -129,7 +129,11 @@ def strip_path_prefix(path): ) def test_file_imports(rel_path, rv): """Test for import errors on a file""" - if rv != "No import errors": + if os.path.exists(".astro/dag_integrity_exceptions.txt"): + with open(".astro/dag_integrity_exceptions.txt", "r") as f: + exceptions = f.readlines() + print(f"Exceptions: {exceptions}") + if (rv != "No import errors") and rel_path not in exceptions: # If rv is not "No import errors," consider it a failed test raise Exception(f"{rel_path} failed to import with message \n {rv}") else: