EqualExperts / dbt-unit-testing

This dbt package contains macros to support unit testing that can be (re)used across dbt projects.
MIT License
413 stars 77 forks source link

dbt crashes when a test file contains >1 test and is named after a macro (`'dict' object is not callable`) #216

Open alexzorin opened 3 months ago

alexzorin commented 3 months ago

Hello again!

I have included a simple proof-of-concept repository for this issue: https://github.com/alexzorin/dbt-unit-test-macro-crash-poc. You can clone it, run dbt deps and dbt build --full-refresh to observe the behavior.

What I have observed is when:

then dbt test will crash with the following error:

❯ dbt test
23:43:21  Running with dbt=1.8.2
23:43:22  Registered adapter: duckdb=1.8.1
23:43:22  Found 1 model, 3 data tests, 596 macros
23:43:22  
23:43:22  Concurrency: 1 threads (target='dev')
23:43:22  
23:43:22  1 of 3 START test example_macro ................................................ [RUN]
23:43:22  1 of 3 ERROR example_macro ..................................................... [ERROR in 0.07s]
23:43:22  2 of 3 START test not_null_my_first_dbt_model_id ............................... [RUN]
23:43:22  2 of 3 PASS not_null_my_first_dbt_model_id ..................................... [PASS in 0.02s]
23:43:22  3 of 3 START test unique_my_first_dbt_model_id ................................. [RUN]
23:43:22  3 of 3 PASS unique_my_first_dbt_model_id ....................................... [PASS in 0.01s]
23:43:22  
23:43:22  Finished running 3 data tests in 0 hours 0 minutes and 0.16 seconds (0.16s).
23:43:22  
23:43:22  Completed with 1 error and 0 warnings:
23:43:22  
23:43:22    Compilation Error in test example_macro (tests/example_macro.sql)
  'dict' object is not callable

  > in macro build_model_complete_sql (macros/sql_builders.sql)
  > called by macro build_test_queries (macros/tests.sql)
  > called by macro build_configuration_and_test_queries (macros/tests.sql)
  > called by macro test (macros/tests.sql)
  > called by test example_macro (tests/example_macro.sql)
23:43:22  
23:43:22  Done. PASS=2 WARN=0 ERROR=1 SKIP=0 TOTAL=3

It is possible to work around the issue by:

You can try those workarounds in the sample repo.

We are (indirectly) using this package for testing of macros as well as models, and it would be really helpful to not have this constraint around naming, naming convention helps us track test coverage.

Thank you once again!

shellyYG commented 3 months ago

Vote for this, having same issue too

psousa50 commented 1 month ago

Hi all,

sorry for the late response 😞

I'm a bit short of time right now but if you are still experiencing this issue I can take a look