I have some unit tests that I’ve written within a model’s configuration (i.e. YAML) file. Whenever I attempt to run them, they always fail with the following error: “cannot access local variable ‘connection’ where it is not associated with a value”.
I’ve already upgraded my dbt-core version to 1.10.15, and my Snowflake plugin to 1.10.3, which are both the latest versions as of the time of creating this post.
I created the most minimal model as possible, just to rule out as many factors as possible. This is my model’s SQL:
SELECT * from {{ ref('test_simple') }}
And this is my model’s YAML:
version: 2
models:
- name: barebones
unit_tests:
- name: test_barebones
model: barebones
given:
- input: ref('test_simple')
format: dict
rows:
- { id: 123, money_cents: 123, currency_code: USD }
expect:
format: dict
rows:
- { id: 123, money_cents: 123, currency_code: USD }
Here is a bit of the stack trace when I run the tests with debug mode:
00:01:58 Snowflake adapter: Error running SQL: macro drop_relation
00:01:58 Snowflake adapter: Rolling back transaction.
00:01:58 Runtime Error in unit_test test_barebones (models/intermediate/kafka/barebones.yml)
An error occurred during execution of unit test 'test_barebones'. There may be an error in the unit test definition: check the data types.
Runtime Error
cannot access local variable 'connection' where it is not associated with a value