Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize invocation context before test fixture creation. #9529

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240206-161331.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Initialize invocation context before test fixtures are built.
time: 2024-02-06T16:13:31.04575-05:00
custom:
Author: peterallenwebb
Issue: '#9489'
13 changes: 12 additions & 1 deletion core/dbt/tests/fixtures/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from dbt.mp_context import get_mp_context
from dbt.parser.manifest import ManifestLoader
from dbt_common.context import set_invocation_context
from dbt_common.exceptions import CompilationError, DbtDatabaseError
from dbt.context.providers import generate_runtime_macro_context
import dbt.flags as flags
Expand Down Expand Up @@ -492,12 +493,23 @@ def get_tables_in_schema(self):
return {model_name: materialization for (model_name, materialization) in result}


# Housekeeping that needs to be done before we start setting up any test fixtures.
@pytest.fixture(scope="class")
def initialization() -> None:
# Create an "invocation context," which dbt application code relies on.
set_invocation_context(os.environ)

# Enable caches used between test runs, for better testing performance.
enable_test_caching()


# This is the main fixture that is used in all functional tests. It pulls in the other
# fixtures that are necessary to set up a dbt project, and saves some of the information
# in a TestProjInfo class, which it returns, so that individual test cases do not have
# to pull in the other fixtures individually to access their information.
@pytest.fixture(scope="class")
def project(
initialization,
clean_up_logging,
project_root,
profiles_root,
Expand All @@ -518,7 +530,6 @@ def project(
# Logbook warnings are ignored so we don't have to fork logbook to support python 3.10.
# This _only_ works for tests in `tests/` that use the project fixture.
warnings.filterwarnings("ignore", category=DeprecationWarning, module="logbook")
enable_test_caching()
log_flags = Namespace(
LOG_PATH=logs_dir,
LOG_FORMAT="json",
Expand Down
Loading