diff --git a/tests/dbt/test_graph.py b/tests/dbt/test_graph.py index 6e11db691c..cdeac44a86 100644 --- a/tests/dbt/test_graph.py +++ b/tests/dbt/test_graph.py @@ -51,12 +51,20 @@ SAMPLE_DBT_LS_OUTPUT = Path(__file__).parent.parent / "sample/sample_dbt_ls.txt" SOURCE_RENDERING_BEHAVIOR = SourceRenderingBehavior(os.getenv("SOURCE_RENDERING_BEHAVIOR", "none")) +# File and directory names to skip when copying dbt project trees in tests (keeps fixture output deterministic). +_DBT_PROJECT_COPY_IGNORED_FILE_AND_DIR_NAMES = (".user.yml", ".DS_Store", "logs", "target") + if AIRFLOW_VERSION.major >= _AIRFLOW3_MAJOR_VERSION: object_storage_path = "airflow.sdk.ObjectStoragePath" else: object_storage_path = "airflow.io.path.ObjectStoragePath" +def _ignore_when_copying_dbt_project(directory: str, names: list[str]) -> list[str]: + """Names to skip in copytree so the fixture tree is deterministic.""" + return [name for name in names if name in _DBT_PROJECT_COPY_IGNORED_FILE_AND_DIR_NAMES] + + @pytest.fixture def tmp_dbt_project_dir(): """ @@ -66,9 +74,7 @@ def tmp_dbt_project_dir(): tmp_dir = Path(tempfile.mkdtemp()) target_proj_dir = tmp_dir / DBT_PROJECT_NAME - shutil.copytree(source_proj_dir, target_proj_dir) - shutil.rmtree(target_proj_dir / "logs", ignore_errors=True) - shutil.rmtree(target_proj_dir / "target", ignore_errors=True) + shutil.copytree(source_proj_dir, target_proj_dir, ignore=_ignore_when_copying_dbt_project) yield tmp_dir shutil.rmtree(tmp_dir, ignore_errors=True) # delete directory @@ -83,9 +89,7 @@ def tmp_altered_dbt_project_dir(): tmp_dir = Path(tempfile.mkdtemp()) target_proj_dir = tmp_dir / ALTERED_DBT_PROJECT_NAME - shutil.copytree(source_proj_dir, target_proj_dir) - shutil.rmtree(target_proj_dir / "logs", ignore_errors=True) - shutil.rmtree(target_proj_dir / "target", ignore_errors=True) + shutil.copytree(source_proj_dir, target_proj_dir, ignore=_ignore_when_copying_dbt_project) yield tmp_dir shutil.rmtree(tmp_dir, ignore_errors=True) # delete directory