Skip to content

Commit

Permalink
(#2095) fix incorrect SKIP count in stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin committed Apr 9, 2020
1 parent fd4a33e commit e5b004b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
4 changes: 4 additions & 0 deletions core/dbt/contracts/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def skipped(self):
class WritableRunModelResult(PartialResult):
skip: bool = False

@property
def skipped(self):
return self.skip


@dataclass
class RunModelResult(WritableRunModelResult):
Expand Down
19 changes: 4 additions & 15 deletions test/integration/001_simple_copy_test/test_simple_copy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import io
import json
import os
from pytest import mark

from test.integration.base import DBTIntegrationTest, use_profile
from dbt.logger import log_manager


class BaseTestSimpleCopy(DBTIntegrationTest):
Expand Down Expand Up @@ -409,24 +407,14 @@ def project_config(self):
"data-paths": [self.dir("seed-initial")],
})

def setUp(self):
super().setUp()
self.initial_stdout = log_manager.stdout
self.initial_stderr = log_manager.stderr
self.stringbuf = io.StringIO()
log_manager.set_output_stream(self.stringbuf)

def tearDown(self):
log_manager.set_output_stream(self.initial_stdout, self.initial_stderr)
super().tearDown()

def seed_get_json(self, expect_pass=True):
self.run_dbt(
results, output = self.run_dbt_and_capture(
['--debug', '--log-format=json', '--single-threaded', 'seed'],
expect_pass=expect_pass
)

logs = []
for line in self.stringbuf.getvalue().split('\n'):
for line in output.split('\n'):
try:
log = json.loads(line)
except ValueError:
Expand All @@ -435,6 +423,7 @@ def seed_get_json(self, expect_pass=True):
if log['extra'].get('run_state') != 'internal':
continue
logs.append(log)

self.assertGreater(len(logs), 0)
return logs

Expand Down
4 changes: 3 additions & 1 deletion test/integration/021_concurrency_test/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test__postgres__concurrency(self):

self.run_sql_file("update.sql")

results = self.run_dbt(expect_pass=False)
results, output = self.run_dbt_and_capture(expect_pass=False)
self.assertEqual(len(results), 7)

self.assertTablesEqual("seed", "view_model")
Expand All @@ -36,6 +36,8 @@ def test__postgres__concurrency(self):
self.assertTableDoesNotExist("invalid")
self.assertTableDoesNotExist("skip")

self.assertIn('PASS=5 WARN=0 ERROR=1 SKIP=1 TOTAL=7', output)

@use_profile('snowflake')
def test__snowflake__concurrency(self):
self.run_sql_file("seed.sql")
Expand Down
17 changes: 17 additions & 0 deletions test/integration/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import io
import random
import shutil
import tempfile
Expand Down Expand Up @@ -537,6 +538,22 @@ def run_dbt(self, args=None, expect_pass=True, strict=True, parser=True, profile

return res


def run_dbt_and_capture(self, *args, **kwargs):
try:
initial_stdout = log_manager.stdout
initial_stderr = log_manager.stderr
stringbuf = io.StringIO()
log_manager.set_output_stream(stringbuf)

res = self.run_dbt(*args, **kwargs)
stdout = stringbuf.getvalue()

finally:
log_manager.set_output_stream(initial_stdout, initial_stderr)

return res, stdout

def run_dbt_and_check(self, args=None, strict=True, parser=False, profiles_dir=True):
log_manager.reset_handlers()
if args is None:
Expand Down

0 comments on commit e5b004b

Please sign in to comment.