diff --git a/core/dbt/include/global_project/macros/schema_tests/accepted_values.sql b/core/dbt/include/global_project/macros/schema_tests/accepted_values.sql index ee81a7a4d9c..b9102a85cd1 100644 --- a/core/dbt/include/global_project/macros/schema_tests/accepted_values.sql +++ b/core/dbt/include/global_project/macros/schema_tests/accepted_values.sql @@ -2,6 +2,7 @@ {% macro test_accepted_values(model, values) %} {% set column_name = kwargs.get('column_name', kwargs.get('field')) %} +{% set quote_values = kwargs.get('quote', True) %} with all_values as ( @@ -20,9 +21,12 @@ validation_errors as ( from all_values where value_field not in ( {% for value in values -%} - - '{{ value }}' {% if not loop.last -%} , {%- endif %} - + {% if quote_values -%} + '{{ value }}' + {%- else -%} + {{ value }} + {%- endif -%} + {%- if not loop.last -%},{%- endif %} {%- endfor %} ) ) diff --git a/test/integration/008_schema_tests_test/models-v2/models/schema.yml b/test/integration/008_schema_tests_test/models-v2/models/schema.yml index b37c6261f77..728cd510a25 100644 --- a/test/integration/008_schema_tests_test/models-v2/models/schema.yml +++ b/test/integration/008_schema_tests_test/models-v2/models/schema.yml @@ -28,7 +28,14 @@ models: - name: favorite_color description: "The user's favorite color" tests: - - accepted_values: { values: ['blue', 'green'] } + - accepted_values: { values: ['blue', 'green'], quote: true } + - name: fav_number + description: "The user's favorite number" + tests: + - accepted_values: + values: [3.14159265] + quote: false + - name: table_summary description: "The summary table" diff --git a/test/integration/008_schema_tests_test/test_schema_v2_tests.py b/test/integration/008_schema_tests_test/test_schema_v2_tests.py index d20a27e684e..31298fa7f73 100644 --- a/test/integration/008_schema_tests_test/test_schema_v2_tests.py +++ b/test/integration/008_schema_tests_test/test_schema_v2_tests.py @@ -32,7 +32,7 @@ def test_postgres_schema_tests(self): self.assertEqual(len(results), 5) test_results = self.run_schema_validations() # If the disabled model's tests ran, there would be 19 of these. - self.assertEqual(len(test_results), 18) + self.assertEqual(len(test_results), 19) for result in test_results: # assert that all deliberately failing tests actually fail