Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from dbeatty10/fix/run-result-status
Browse files Browse the repository at this point in the history
Infer the node name from the unique_id
  • Loading branch information
Kyle Wigley authored Jan 7, 2021
2 parents 104a630 + 5efc098 commit cc9251e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pytest_dbt_adapter/sequences/data_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ sequence:
length: fact.test.length
names: fact.test.names
attributes:
passing.fail: false
failing.fail: true
passing.status: pass
failing.status: fail
4 changes: 2 additions & 2 deletions pytest_dbt_adapter/sequences/data_test_ephemeral_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ sequence:
length: fact.test.length
names: fact.test.names
attributes:
passing.fail: false
failing.fail: true
passing.status: pass
failing.status: fail
- type: dbt
cmd: run
- type: run_results
Expand Down
18 changes: 15 additions & 3 deletions pytest_dbt_adapter/spec_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ def _build_expected_attributes_dict(
attributes[name][keypath] = value
return attributes

@staticmethod
def _get_name(
unique_id: str
) -> str:
""" turn a unique_id into just a node name. """
# The last part of the unique_id is the name
# Example:
# Consider unique_id "test.dbt_test_project.failing"
# Then the name is "failing"
return unique_id.split(".")[-1]

def step_run_results(self, sequence_item, tmpdir):
path = os.path.join(tmpdir, 'project', 'target', 'run_results.json')

Expand Down Expand Up @@ -302,7 +313,8 @@ def step_run_results(self, sequence_item, tmpdir):

for result in results:
try:
name = result['node']['name']
unique_id = result['unique_id']
name = self._get_name(unique_id)
except KeyError as exc:
raise DBTException(
f'Invalid result, missing required key {exc}'
Expand All @@ -323,8 +335,8 @@ def step_run_results(self, sequence_item, tmpdir):

for result in results:
try:
node = result['node']
name = node['name']
unique_id = result['unique_id']
name = self._get_name(unique_id)
except KeyError as exc:
raise DBTException(
f'Invalid result, missing required key {exc}'
Expand Down

0 comments on commit cc9251e

Please sign in to comment.