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

Fix project dir argument when running debug (#1733) #1989

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions core/dbt/task/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def __init__(self, args, config):
self.profiles_dir = getattr(self.args, 'profiles_dir',
dbt.config.PROFILES_DIR)
self.profile_path = os.path.join(self.profiles_dir, 'profiles.yml')
self.project_path = os.path.join(os.getcwd(), 'dbt_project.yml')
self.project_dir = args.project_dir or os.getcwd()
self.project_path = os.path.join(self.project_dir, 'dbt_project.yml')
self.cli_vars = dbt.utils.parse_cli_vars(
getattr(self.args, 'vars', '{}')
)
Expand Down Expand Up @@ -125,7 +126,7 @@ def _load_project(self):
return red('ERROR not found')

try:
self.project = Project.from_current_directory(self.cli_vars)
self.project = Project.from_project_root(self.project_dir, self.cli_vars)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line is too long per our styleguide:

core/dbt/task/debug.py:129:80: E501 line too long (85 > 79 characters)

via: https://circleci.com/gh/fishtown-analytics/dbt/19769?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

Can you split this onto two lines?

except dbt.exceptions.DbtConfigError as exc:
self.project_fail_details = str(exc)
return red('ERROR invalid')
Expand Down
25 changes: 25 additions & 0 deletions test/integration/049_dbt_debug_test/test_debug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from test.integration.base import DBTIntegrationTest, use_profile
import os
import re
import yaml

import pytest

Expand Down Expand Up @@ -103,3 +104,27 @@ def test_postgres_badproject(self):
self.assertIn('ERROR invalid', line)
elif line.strip().startswith('profiles.yml file'):
self.assertNotIn('ERROR invalid', line)

@use_profile('postgres')
def test_postgres_not_found_project_dir(self):
self.use_default_project()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to call use_default_project unless you do things with the project/profile as part of the test - setUp will call it (some old tests still have it, so I understand where this came from!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right @beckjake . I did not realize that it is called in setUp method. I will take it into account for the next time, thanks!

self.run_dbt(['debug', '--project-dir', 'nopass'])
splitout = self.capsys.readouterr().out.split('\n')
for line in splitout:
if line.strip().startswith('dbt_project.yml file'):
self.assertIn('ERROR not found', line)

@use_profile('postgres')
def test_postgres_invalid_project_outside_current_dir(self):
# create a dbt_project.yml
project_config = {
'invalid-key': 'not a valid key in this project'
}
os.makedirs('custom', exist_ok=True)
with open("custom/dbt_project.yml", 'w') as f:
yaml.safe_dump(project_config, f, default_flow_style=True)
self.run_dbt(['debug', '--project-dir', 'custom'])
splitout = self.capsys.readouterr().out.split('\n')
for line in splitout:
if line.strip().startswith('dbt_project.yml file'):
self.assertIn('ERROR invalid', line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a newline at the end of this file? looking at stuff in the terminal can get annoying without trailing newlines.