The problem I’m having
we have macros that use this.name to refer to the name of the model. In unit tests of models that use this macro, I get the error:
Compilation Error in unit_test my_test (models\mytest.yml)
'None' has no attribute 'name'
The context of why I’m trying to do this
I want to unit test our macros. In these macros “this.name” is used to get the name of the model. (e.g. as logging information)
What I’ve already tried
I added to the given section of the unit test the following for “this”:
given:
- input: this
format: sql
rows: |
select 1
This changes the error message to:
Compilation Error in unit_test my_test (models\mytest.yml)
'str object' has no attribute 'name'
I also tried to override somehow “this.name” but as it is no macro or variable, it didn’t work / I don’t know how.
Since I am sure that others use this.name as well in their code: How do you unit test models / macros with this.name?