# using vargs in custom tests

**URL:** <https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009>\
**Category:** Help\
**Tags:** testing\
**Created:** [February 27, 2023, 11:28am UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009 "2023-02-27T11:28:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnny.huang](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@johnny.huang](https://discourse.getdbt.com/u/johnny.huang)\
**Post date:** [February 27, 2023, 11:28am UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009/1 "2023-02-27T11:28:51Z")

</div>

## The problem I’m having

I’d like to extend the current ‘unique’ test to be able to take a variable list of parameters so it can test if the concatenation of the list of columns is unique i.e. col1 || col2 || col3

## The context of why I’m trying to do this

I have tables that need to have this assertion tested.

## What I’ve already tried

looking through the docs, it seems custom tests must take named arguements atm.

## Some example code or error messages

N/A

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [February 27, 2023, 1:29pm UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009/3 "2023-02-27T13:29:11Z")

</div>

This already exists in the dbt-utils package: [https://github.com/dbt-labs/dbt-utils#unique\_combination\_of\_columns-source](https://github.com/dbt-labs/dbt-utils#unique_combination_of_columns-source)

Note: `@Owen` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1677504542423839?thread_ts=1677497366.808539&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [February 27, 2023, 1:36pm UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009/4 "2023-02-27T13:36:45Z")

</div>

Thanks \<@U0291GP2AQ0\>, I was doing it in a more complex way 😅

Note: `@Bruno de Lima` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1677504997968509?thread_ts=1677497366.808539&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![johnny.huang](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@johnny.huang](https://discourse.getdbt.com/u/johnny.huang)\
**Post date:** [February 27, 2023, 7:55pm UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009/5 "2023-02-27T19:55:38Z")

</div>

oh nice! I didn’t realise that!! below is what I tried but am now getting a compilation error complaining about the macro takes no keyword argument ‘column\_name’ which I can’t control… ideas?

```
  - name: METRIC_NAME
    tests:
      - dbt_utils.unique_combination_of_columns:
          combination_of_columns:
            - GROUP_NAME
            - METRIC_NAME
          quote_columns: false

```

Compilation Error in test dbt\_utils\_unique\_combination\_of\_columns\_SEED\_METRIC\_LIST\_CNMS\_METRIC\_NAME\_\_GROUP\_NAME\_\_METRIC\_NAME\_\_False (seeds/Metadata/metadata.yml)  
macro ‘dbt\_macro\_\_test\_unique\_combination\_of\_columns’ takes no keyword argument ‘column\_name’

---

<div class="post-metadata">

**Author:** ![brunoszdl](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/brunoszdl/32/4113_2.png) [@brunoszdl](https://discourse.getdbt.com/u/brunoszdl)\
**Post date:** [February 27, 2023, 8:22pm UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009/6 "2023-02-27T20:22:59Z")

</div>

Try to define the test below the name of the seed, not below the name of the column

---

<div class="post-metadata">

**Author:** ![brunoszdl](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/brunoszdl/32/4113_2.png) [@brunoszdl](https://discourse.getdbt.com/u/brunoszdl)\
**Post date:** [February 27, 2023, 8:24pm UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009/7 "2023-02-27T20:24:54Z")

</div>

Like this:

```auto
version: 2

seeds:
  - name: your_seed
    tests:
      - dbt_utils.unique_combination_of_columns:
          combination_of_columns:
            - GROUP_NAME
            - METRIC_NAME
    columns:
      - name: METRIC_NAME

```

just check the indentation.

Just explaining a little bit more:

- When you put the test below the model/seed name, dbt assumes you are passing to the test an arg called “model” with the name of your model/seed.
- When you put the test below the column name, dbt assumes you are passing to the test two args, model like before, and column\_name, which is the name of your column.

This specific test does not accept a column\_name arg, because it is not designed for a specific column, but a group of them. This group of columns is passed by a custom arg called “combination\_of\_columns” that is why you have to specify it in the .yml.

---

<div class="post-metadata">

**Author:** ![johnny.huang](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@johnny.huang](https://discourse.getdbt.com/u/johnny.huang)\
**Post date:** [February 27, 2023, 8:57pm UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009/8 "2023-02-27T20:57:24Z")

</div>

thank you so much!! much appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [March 6, 2023, 8:57pm UTC](https://discourse.getdbt.com/t/using-vargs-in-custom-tests/7009/9 "2023-03-06T20:57:35Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
