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

route logs to dbt-core/logs instead of each test folder #4711

Merged
merged 15 commits into from
Feb 10, 2022
Merged
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
22 changes: 20 additions & 2 deletions core/dbt/tests/fixtures/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import random
import time
from argparse import Namespace
from datetime import datetime
import dbt.flags as flags

from dbt.config.runtime import RuntimeConfig
from dbt.adapters.factory import get_adapter, register_adapter
from dbt.events.functions import setup_event_logger
Expand Down Expand Up @@ -98,12 +100,13 @@ def project_config_update():


@pytest.fixture
def dbt_project_yml(project_root, project_config_update):
def dbt_project_yml(project_root, project_config_update, logs_dir):
project_config = {
"config-version": 2,
"name": "test",
"version": "0.1.0",
"profile": "test",
"log-path": logs_dir
}
if project_config_update:
project_config.update(project_config_update)
Expand Down Expand Up @@ -231,6 +234,20 @@ def project_files(project_root, models, macros, snapshots, seeds, tests):
write_project_files(project_root, "tests", tests)


@pytest.fixture(scope="session")
def logs_dir(request):
# create a directory name that will be unique per test session
_randint = random.randint(0, 9999)
_runtime_timedelta = (datetime.utcnow() - datetime(1970, 1, 1, 0, 0, 0))
_runtime = (
(int(_runtime_timedelta.total_seconds() * 1e6)) +
_runtime_timedelta.microseconds
)
prefix = f'test{_runtime}{_randint:04}'

return os.path.join(request.config.rootdir, 'logs', prefix)


class TestProjInfo:
def __init__(
self,
Expand Down Expand Up @@ -267,8 +284,9 @@ def project(
project_files,
shared_data_dir,
test_data_dir,
logs_dir,
):
setup_event_logger("logs")
setup_event_logger(logs_dir)
os.chdir(project_root)
# Return whatever is needed later in tests but can only come from fixtures, so we can keep
# the signatures in the test signature to a minimum.
Expand Down