diff --git a/tests/functional/partial_parsing/test_partial_parsing.py b/tests/functional/partial_parsing/test_partial_parsing.py index 9e24a7aaaa2..88a16058f8b 100644 --- a/tests/functional/partial_parsing/test_partial_parsing.py +++ b/tests/functional/partial_parsing/test_partial_parsing.py @@ -11,6 +11,7 @@ run_dbt_and_capture, rename_dir, ) +from tests.functional.utils import up_one from dbt.tests.fixtures.project import write_project_files from tests.functional.partial_parsing.fixtures import ( model_one_sql, @@ -881,11 +882,12 @@ def local_dependency_files(self): } def rename_project_root(self, project, new_project_root): - rename_dir(project.project_root, new_project_root) - project.project_root = new_project_root - # flags.project_dir is set during the project test fixture, and is persisted across run_dbt calls, - # so it needs to be reset between invocations - flags.set_from_args(Namespace(PROJECT_DIR=new_project_root), None) + with up_one(new_project_root): + rename_dir(project.project_root, new_project_root) + project.project_root = new_project_root + # flags.project_dir is set during the project test fixture, and is persisted across run_dbt calls, + # so it needs to be reset between invocations + flags.set_from_args(Namespace(PROJECT_DIR=new_project_root), None) @pytest.fixture(scope="class", autouse=True) def initial_run_and_rename_project_dir(self, project, local_dependency_files): diff --git a/tests/functional/utils.py b/tests/functional/utils.py index 26d31c752ac..ddfe367856b 100644 --- a/tests/functional/utils.py +++ b/tests/functional/utils.py @@ -1,13 +1,14 @@ import os from contextlib import contextmanager +from typing import Optional from pathlib import Path @contextmanager -def up_one(): +def up_one(return_path: Optional[Path] = None): current_path = Path.cwd() os.chdir("../") try: yield finally: - os.chdir(current_path) + os.chdir(return_path or current_path)