Skip to content

Commit 372edaa

Browse files
authored
305 save_test_history with dbt build (#78)
* Add schema with _seeds postfix to the drop list * Add dbt build cli command * Add support for build command in save_test_history * Modify expected test history to accommodate with additional tests * Add dbt build save history test
1 parent 9c9bc8b commit 372edaa

5 files changed

Lines changed: 26 additions & 4 deletions

File tree

integration_tests/macros/drop_all_schemas.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
schema_name + '_re_internal',
66
schema_name + '_raw',
77
schema_name + '_expected',
8-
schema_name + '_dbt_test__audit'
8+
schema_name + '_dbt_test__audit',
9+
schema_name + '_seeds'
910
] %}
1011
{{ return (schemas) }}
1112
{% endmacro %}

integration_tests/python_tests/test_monitoring.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import yaml
44
import json
55
from datetime import datetime, timedelta
6-
from .utils.run import dbt_seed, dbt_run, dbt_test, dbt_command
6+
from .utils.run import dbt_seed, dbt_run, dbt_test, dbt_command, dbt_build
77

88
RUN_TIME = datetime(2021, 5, 2, 0, 0, 0)
99

@@ -52,6 +52,8 @@ def test_monitoring(db, source_schema):
5252
)
5353

5454
dbt_test('--select test_re_data_anomalies test_re_data_metrics test_re_data_z_score re_data_metrics transformed', db, dbt_vars)
55+
# dbt build will "duplicate" saved test result history
56+
dbt_build('--select test_re_data_anomalies test_re_data_metrics test_re_data_z_score re_data_metrics transformed', db, dbt_vars)
5557

5658
# tests test_history seperately, because those are actually added to DB after running
5759
# dbt test command

integration_tests/python_tests/utils/run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ def dbt_run(args, for_db, dbt_vars):
1717
dbt_command(f'dbt run --full-refresh --fail-fast {args}', for_db, dbt_vars, threads=4)
1818

1919
def dbt_test(args, for_db, dbt_vars):
20-
dbt_command(f'dbt test --store-failures --fail-fast {args}', for_db, dbt_vars, threads=4)
20+
dbt_command(f'dbt test --store-failures --fail-fast {args}', for_db, dbt_vars, threads=4)
21+
22+
def dbt_build(args, for_db, dbt_vars):
23+
dbt_command(f'dbt build --full-refresh --store-failures --fail-fast {args}', for_db, dbt_vars, threads=4)

integration_tests/seeds/monitoring/expected_test_history.csv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ RE_DATA_METRICS,---,_buy_events___3,Pass,---,0,ERROR
1515
RE_DATA_METRICS,---,ref_buy_events_,Pass,---,0,ERROR
1616
RE_DATA_METRICS,---,ref_buy_events_,Pass,---,0,ERROR
1717
RE_DATA_METRICS,---,ref_buy_events_,Pass,---,0,ERROR
18+
BUY_EVENTS,---,ts_row_count__1,Pass,---,0,ERROR
19+
TEST_RE_DATA_Z_SCORE,---,pected_z_score_,Pass,---,0,ERROR
20+
TEST_RE_DATA_METRICS,---,pected_metrics_,Pass,---,0,ERROR
21+
TEST_RE_DATA_ANOMALIES,---,cted_anomalies_,Pass,---,0,ERROR
22+
BUY_EVENTS,---,null__freshness,Pass,---,0,ERROR
23+
BUY_EVENTS,VALUE2,alue2__min__200,Pass,---,0,ERROR
24+
BUY_EVENTS,---,0__row_count__0,Pass,---,0,ERROR
25+
BUY_EVENTS,---,_table_rows__10,Pass,---,0,ERROR
26+
BUY_EVENTS,VALUE1,ulls_percent__0,Pass,---,0,ERROR
27+
BUY_EVENTS,VALUE1,alue1__min__100,Pass,---,0,ERROR
28+
BUY_EVENTS,VALUE1,__nulls_percent,Pass,---,0,ERROR
29+
BUY_EVENTS,VALUE1,alue1__min__107,Pass,---,0,ERROR
30+
RE_DATA_METRICS,---,_buy_events___3,Pass,---,0,ERROR
31+
RE_DATA_METRICS,---,ref_buy_events_,Pass,---,0,ERROR
32+
RE_DATA_METRICS,---,ref_buy_events_,Pass,---,0,ERROR
33+
RE_DATA_METRICS,---,ref_buy_events_,Pass,---,0,ERROR

macros/run_end/save_results_history.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% macro save_test_history(results) %}
33
-- depends_on: {{ ref('re_data_test_history') }}
44
{% set command = flags.WHICH %}
5-
{% if execute and results and command == 'test' %}
5+
{% if execute and results and command in ('test', 'build') %}
66
{% set tests = [] %}
77
{% for el in results %}
88
{% if el.node.resource_type.value == 'test' %}

0 commit comments

Comments
 (0)