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

dbt debug should return 1 when one of the tests fail #3018

Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Contributors:

## dbt 0.19.0 (Release TBD)

### Fixes

- Fix exit code from dbt debug not returning a failure when one of the tests fail ([#3017](https:/fishtown-analytics/dbt/issues/3017))

sdebruyn marked this conversation as resolved.
Show resolved Hide resolved
## dbt 0.19.0rc2 (January 14, 2021)


Expand Down
16 changes: 14 additions & 2 deletions core/dbt/task/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
{url}
'''.lstrip()


MISSING_PROFILE_MESSAGE = '''
dbt looked for a profiles.yml file in {path}, but did
not find one. For more information on configuring your profile, consult the
Expand Down Expand Up @@ -90,6 +89,7 @@ def __init__(self, args, config):
self.profile_name: Optional[str] = None
self.project: Optional[Project] = None
self.project_fail_details = ''
self.any_failure = False
self.messages: List[str] = []

@property
Expand All @@ -111,7 +111,7 @@ def path_info(self):
def run(self):
if self.args.config_dir:
self.path_info()
return
return not self.any_failure

version = get_installed_version().to_version_string(skip_matcher=True)
print('dbt version: {}'.format(version))
Expand All @@ -129,6 +129,11 @@ def run(self):
print(message)
print('')

return not self.any_failure

def interpret_results(self, results):
return results

def _load_project(self):
if not os.path.exists(self.project_path):
self.project_fail_details = FILE_NOT_FOUND
Expand Down Expand Up @@ -245,6 +250,7 @@ def _load_profile(self):
self.messages.append(MISSING_PROFILE_MESSAGE.format(
path=self.profile_path, url=ProfileConfigDocs
))
self.any_failure = True
return red('ERROR not found')

try:
Expand Down Expand Up @@ -283,6 +289,7 @@ def test_git(self):
dbt.clients.system.run_cmd(os.getcwd(), ['git', '--help'])
except dbt.exceptions.ExecutableError as exc:
self.messages.append('Error from git --help: {!s}'.format(exc))
self.any_failure = True
return red('ERROR')
return green('OK found')

Expand Down Expand Up @@ -310,6 +317,8 @@ def test_configuration(self):
def _log_project_fail(self):
if not self.project_fail_details:
return

self.any_failure = True
if self.project_fail_details == FILE_NOT_FOUND:
return
print('Project loading failed for the following reason:')
Expand All @@ -319,6 +328,8 @@ def _log_project_fail(self):
def _log_profile_fail(self):
if not self.profile_fail_details:
return

self.any_failure = True
if self.profile_fail_details == FILE_NOT_FOUND:
return
print('Profile loading failed for the following reason:')
Expand Down Expand Up @@ -347,6 +358,7 @@ def _connection_result(self):
result = self.attempt_connection(self.profile)
if result is not None:
self.messages.append(result)
self.any_failure = True
return red('ERROR')
return green('OK connection ok')

Expand Down
14 changes: 7 additions & 7 deletions test/integration/049_dbt_debug_test/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ def test_postgres_ok(self):

@use_profile('postgres')
def test_postgres_nopass(self):
self.run_dbt(['debug', '--target', 'nopass'])
self.run_dbt(['debug', '--target', 'nopass'], expect_pass=False)
self.assertGotValue(re.compile(r'\s+profiles\.yml file'), 'ERROR invalid')

@use_profile('postgres')
def test_postgres_wronguser(self):
self.run_dbt(['debug', '--target', 'wronguser'])
self.run_dbt(['debug', '--target', 'wronguser'], expect_pass=False)
self.assertGotValue(re.compile(r'\s+Connection test'), 'ERROR')

@use_profile('postgres')
def test_postgres_empty_target(self):
self.run_dbt(['debug', '--target', 'none_target'])
self.run_dbt(['debug', '--target', 'none_target'], expect_pass=False)
self.assertGotValue(re.compile(r"\s+output 'none_target'"), 'misconfigured')


Expand Down Expand Up @@ -110,7 +110,7 @@ def capsys(self, capsys):
def test_postgres_empty_project(self):
with open('dbt_project.yml', 'w') as f:
pass
self.run_dbt(['debug', '--profile', 'test'])
self.run_dbt(['debug', '--profile', 'test'], expect_pass=False)
splitout = self.capsys.readouterr().out.split('\n')
for line in splitout:
if line.strip().startswith('dbt_project.yml file'):
Expand All @@ -124,7 +124,7 @@ def test_postgres_badproject(self):
self.use_default_project(overrides={
'invalid-key': 'not a valid key so this is bad project',
})
self.run_dbt(['debug', '--profile', 'test'])
self.run_dbt(['debug', '--profile', 'test'], expect_pass=False)
splitout = self.capsys.readouterr().out.split('\n')
for line in splitout:
if line.strip().startswith('dbt_project.yml file'):
Expand All @@ -134,7 +134,7 @@ def test_postgres_badproject(self):

@use_profile('postgres')
def test_postgres_not_found_project_dir(self):
self.run_dbt(['debug', '--project-dir', 'nopass'])
self.run_dbt(['debug', '--project-dir', 'nopass'], expect_pass=False)
splitout = self.capsys.readouterr().out.split('\n')
for line in splitout:
if line.strip().startswith('dbt_project.yml file'):
Expand All @@ -151,7 +151,7 @@ def test_postgres_invalid_project_outside_current_dir(self):
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'])
self.run_dbt(['debug', '--project-dir', 'custom'], expect_pass=False)
splitout = self.capsys.readouterr().out.split('\n')
for line in splitout:
if line.strip().startswith('dbt_project.yml file'):
Expand Down