From c8b3594e24ee461566fc37a0deb0a77da021a291 Mon Sep 17 00:00:00 2001 From: Pedro Sousa Date: Fri, 5 Jan 2024 12:26:50 +0000 Subject: [PATCH] Run tests only on test command --- macros/tests.sql | 2 +- run-test-on-dbt-version.sh | 36 ------------------------------------ run-tests-on-dbt-version.sh | 6 ++++-- 3 files changed, 5 insertions(+), 39 deletions(-) delete mode 100755 run-test-on-dbt-version.sh diff --git a/macros/tests.sql b/macros/tests.sql index 557118b..67b1a65 100644 --- a/macros/tests.sql +++ b/macros/tests.sql @@ -1,7 +1,7 @@ {% macro test(model_name, test_description='(no description)', options={}) %} {{ dbt_unit_testing.ref_tested_model(model_name) }} - {% if execute %} + {% if execute and flags.WHICH == 'test' %} {% set mocks_and_expectations_json_str = caller() %} {% set model_version = kwargs["version"] | default(kwargs["v"]) | default(none) %} {% set model_node = {"package_name": model.package_name, "name": model_name, "version": model_version} %} diff --git a/run-test-on-dbt-version.sh b/run-test-on-dbt-version.sh deleted file mode 100755 index bd57a0a..0000000 --- a/run-test-on-dbt-version.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -set -e - -if [ -z "$1" ]; then - echo 'Please provide test script to run' - exit 1 -fi - -if [ -z "$2" ]; then - echo 'Please provide profile name' - exit 1 -fi - -if [ -z "$3" ]; then - echo 'Please provide dbt version' - exit 1 -fi - -TEST_SCRIPT="$1" -PROFILE="$2" -DBT_VERSION=$3 - -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -VENV_NAME="venv-$PROFILE" -VENV_FOLDER="$SCRIPT_DIR/$VENV_NAME" - -rm -rf "$VENV_FOLDER" -python3 -m venv "$VENV_FOLDER" - -pip install --upgrade pip setuptools -pip install "dbt-$PROFILE==$DBT_VERSION" - -source "$VENV_FOLDER/bin/activate" - -"$SCRIPT_DIR/$TEST_SCRIPT.sh" "$PROFILE" diff --git a/run-tests-on-dbt-version.sh b/run-tests-on-dbt-version.sh index cc828d0..41b77da 100755 --- a/run-tests-on-dbt-version.sh +++ b/run-tests-on-dbt-version.sh @@ -21,6 +21,8 @@ TEST_SCRIPT="$1" PROFILE="$2" DBT_VERSION=$3 +echo "Running $TEST_SCRIPT on dbt $DBT_VERSION with profile $PROFILE" + SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) VENV_NAME="venv-$PROFILE" VENV_FOLDER="$SCRIPT_DIR/$VENV_NAME" @@ -28,9 +30,9 @@ VENV_FOLDER="$SCRIPT_DIR/$VENV_NAME" rm -rf "$VENV_FOLDER" python3 -m venv "$VENV_FOLDER" +source "$VENV_FOLDER/bin/activate" + pip install --upgrade pip setuptools pip install "dbt-$PROFILE==$DBT_VERSION" -source "$VENV_FOLDER/bin/activate" - "$SCRIPT_DIR/$TEST_SCRIPT.sh" "$PROFILE" "$DBT_VERSION"