Skip to content

Commit 2be7196

Browse files
committed
Update README
1 parent 1c0acee commit 2be7196

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ dbt test --select tag:unit-test
194194
| dbt_unit_testing.mock_source | Mocks a **source** |
195195
| dbt_unit_testing.expect | Defines the Test expectations |
196196
| dbt_unit_testing.expect_no_rows | Used to test if the model returns no rows |
197+
| dbt_unit_testing.model | Allows the use of the model object |
197198

198199
## Test Examples
199200

@@ -703,6 +704,24 @@ FROM
703704

704705
In this example, the `activity_details` column, which is a struct, is transformed into a JSON string using `to_json_string(##column##)` before the execution of the unit test. This transformation facilitates operations like grouping and EXCEPT in BigQuery by converting the struct into a more manageable string format.
705706

707+
## The `model` object
708+
709+
You can use the model object in your dbt models to access model properties, like this:
710+
711+
```sql
712+
select model.name as model_name from {{ ref('some_model') }}
713+
```
714+
715+
However this will prevent you from running tests on this model, because when running tests the model object refers to the test itself, not the model being tested.
716+
717+
To overcome this limitation, you can use the `dbt_unit_testing.model` macro, like this:
718+
719+
```sql
720+
select dbt_unit_testing.model().name as model_name from {{ ref('some_model') }}
721+
```
722+
723+
The `dbt_unit_testing.model` macro will return the model object when running the model and when running the tests as well.
724+
706725
## Available Options
707726

708727
| option | description | default | scope* |

0 commit comments

Comments
 (0)