Skip to content

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

@alexzorin

Description

@alexzorin

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:

  • Naming the file literally anything else (like adding a .test.sql suffix), or
  • Only having a single test in the file.

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions