Skip to content

Commit

Permalink
route logs to dbt-core/logs instead of each test folder (#4711)
Browse files Browse the repository at this point in the history
* Initial pass at switching integration tests to pytest

* Move tests/util.py and tests/tables.py into core/dbt/tests

* Attempt to get interop tests to pass, add test/integration to some
Makefile targets

* Move project fixtures into core/dbt/tests/fixtures/project.py

* flake8 and formatting

* Add jaffle_shop fixture

* Add test_quoted_database.py test in simple_copy

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

* Instead of one data_dir provide 'test_data_dir' and 'shared_data_dir'

* update CONVERTING.md

* removed unused import

* used built in request fixture for root dir

* pulled in changes, fixed flake8 error

Co-authored-by: Gerda Shank <gerda@dbtlabs.com>
  • Loading branch information
emmyoop and gshank authored Feb 10, 2022
1 parent 507184f commit d46b197
Showing 1 changed file with 20 additions and 2 deletions.
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

0 comments on commit d46b197

Please sign in to comment.