{"id":13703862,"url":"https://github.com/tnightengale/dbt-meta-testing","last_synced_at":"2025-05-05T09:32:06.847Z","repository":{"id":40421009,"uuid":"315352544","full_name":"tnightengale/dbt-meta-testing","owner":"tnightengale","description":"A dbt SQL package for ensuring documentation and test coverage, with granular control.","archived":false,"fork":false,"pushed_at":"2022-11-18T10:08:53.000Z","size":65,"stargazers_count":116,"open_issues_count":7,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-03T21:04:22.336Z","etag":null,"topics":["dbt","dbt-artifacts","dbt-fundamentals","dbt-macros","dbt-packages","dbt-tests","testing"],"latest_commit_sha":null,"homepage":"","language":"SQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tnightengale.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-23T15:09:09.000Z","updated_at":"2024-07-15T00:04:07.000Z","dependencies_parsed_at":"2022-07-12T18:02:05.783Z","dependency_job_id":null,"html_url":"https://github.com/tnightengale/dbt-meta-testing","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnightengale%2Fdbt-meta-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnightengale%2Fdbt-meta-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnightengale%2Fdbt-meta-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnightengale%2Fdbt-meta-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tnightengale","download_url":"https://codeload.github.com/tnightengale/dbt-meta-testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224439544,"owners_count":17311468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dbt","dbt-artifacts","dbt-fundamentals","dbt-macros","dbt-packages","dbt-tests","testing"],"created_at":"2024-08-02T21:01:00.917Z","updated_at":"2024-11-13T11:30:17.529Z","avatar_url":"https://github.com/tnightengale.png","language":"SQL","funding_links":[],"categories":["Packages"],"sub_categories":[],"readme":"![buildstatus](https://github.com/tnightengale/dbt-meta-testing/workflows/Integration%20Tests/badge.svg)\n\n# dbt Meta Testing\nThis [dbt](https://docs.getdbt.com/docs/introduction) package contains macros to assert test and documentation coverage from\n`dbt_project.yml` configuration settings.\n\n## Table of Contents\n  - [Install](#install)\n  - [Configurations](#configurations)\n    - [Required Tests](#required-tests)\n    - [Required Docs](#required-docs)\n  - [Usage](#usage)\n    - [required_tests (source)](#required_tests-source)\n    - [required_docs (source)](#required_docs-source)\n  - [Contributions](#contributions)\n  - [Testing](#testing)\n    - [Verified Data Warehouses](#verified-data-warehouses)\n\n## Install\nInclude in `packages.yml`:\n\n```yaml\npackages:\n  - package: tnightengale/dbt_meta_testing\n    version: 0.3.6\n```\nFor latest release, see\nhttps://github.com/tnightengale/dbt-meta-testing/releases.\n\n## Configurations\nThis package features two meta configs that can be applied to a dbt project:\n\n1. `+required_tests`\n2. `+required_docs`\n\nRead the dbt documentation\n[here](https://docs.getdbt.com/reference/model-configs) to learn more about\nmodel configurations in dbt.\n\n### Required Tests\nTo require test coverage, define the `+required_tests` configuration on a model\npath in `dbt_project.yml`:\n```yaml\n# dbt_project.yml\n...\nmodels:\n  project:\n    +required_docs: true\n    marts:\n      +required_tests: {\"unique.*|not_null\": 1}\n      model_2:\n        +required_tests:\n          \"mocker.*|unique\": 1\n          \"mock_schema_test\": 1\n          \".*data_test\": 1\n```\n\nThe `+required_tests` config must be `None` or a `dict` with `str` keys and `int`\nvalues. YAML dictionaries are accepted.\n\nAll the regular\ndbt configuration hierarchy rules apply. For example, individual model configs\nwill override configs from the `dbt_project.yml`:\n```sql\n# /models/marts/core/your_model.sql\n\n-- This overrides the config in dbt_project.yml, and this model will not require tests\n{{ config(required_tests=None) }}\n\nSELECT\n...\n```\n\u003e **_New in Version 0.3.3_**\n\nThe keys of the config are evaluated against both data and schema tests\n(including any custom tests) using the\n[re.fullmatch](https://docs.python.org/3/library/re.html#re.fullmatch) function.\n\nTherefore, any test restriction which can be expressed in regex can  be\nevaluated.\n\nFor example:\n```yaml\n# dbt_project.yml\n...\nmodels:\n  project:\n    +required_docs: true\n    # The following configuration on the `marts` model path requires\n    # each model in that path to have at least one test that either:\n    #\n    #    1. starts with \"unique\" (note the \".*\" regex suffix) OR (note the \"|\" regex)\n    #    2. is an exact match for the \"not_null\" test.\n\n    marts:\n      +required_tests: {\"unique.*|not_null\": 1}\n```\n\nSchema tests are matched against their common names, (eg. `not_null`,\n`accepted_values`).\n\nData tests are matched against their macro name.\n\nCustom schema tests are matched against their name, eg. `mock_schema_test`:\n\n```yaml\n# models/schema.yml\n...\n    - name: model_2\n      description: \"\"\n      tests:\n        - equal_rowcount:\n            compare_model: ref('model_1')\n      columns:\n          - name: id\n            description: \"The primary key for this table\"\n            tests:\n                - unique\n                - not_null\n                - mock_schema_test\n```\n\nModels that do not meet their configured test minimums, because they either lack\nthe tests or are not documented, will be listed in the\nerror when validated via a `run-operation`:\n```\nusr@home dbt-meta-testing $ dbt run-operation required_tests\nRunning with dbt=0.20.0\nEncountered an error while running operation: Compilation Error in macro required_tests (macros/required_tests.sql)\n  Insufficient test coverage from the 'required_tests' config on the following models:\n  Model: 'model_1' Test: 'not_null' Got: 1 Expected: 2\n  Model: 'model_1' Test: 'mock_schema_test' Got: 0 Expected: 1\n\n  \u003e in macro _evaluate_required_tests (macros/utils/required_tests/evaluate_required_tests.sql)\n  \u003e called by macro required_tests (macros/required_tests.sql)\n  \u003e called by macro required_tests (macros/required_tests.sql)\nusr@home dbt-meta-testing $\n```\n\n### Required Docs\nTo require documentation coverage, define the `+required_docs` configuration on\na model path in `dbt_project.yml`:\n```yaml\n# dbt_project.yml\n...\nmodels:\n    project:\n        +required_docs: true\n```\nThe `+required_docs` config must be a `bool`.\n\nIt also **does not check ephemeral\nmodels**. This is because it cannot leverage `adapter.get_columns_in_relation()`\nmacro on ephemeral models, which it uses to fetch columns from the data\nwarehouse and detect columns without documentation.\n\nWhen applied to a non-ephemeral model, this config will ensure 3 things:\n1. The _model_ has a non-empty description\n2. The _columns_ in the model are specified in the model `.yml`\n3. The _columns_ specified in the model `.yml` have non-empty descriptions\n\nFor example, the following configurations:\n```yaml\n# models/schema.yml\nversion: 2\n\nmodels:\n    - name: model_1\n      description: \"A starter dbt model\"\n      columns:\n          - name: id\n            description: \"\"\n            tests:\n                - unique\n                - not_null\n\n    - name: model_2\n      description: \"\"\n      tests:\n        - equal_rowcount:\n            compare_model: ref('model_1')\n      columns:\n          - name: id\n            description: \"The primary key for this table\"\n            tests:\n                - unique\n                - not_null\n\n```\n\nWhere `model_2` has a column `new` which is not defined in the `.yml` above:\n```sql\n-- models/example/model_2.sql\nselect\n    *,\n    'new' as new\nfrom {{ ref('model_1') }}\nwhere id = 1\n```\n\nAnd all models in the example path require docs:\n```yaml\n# dbt_project.yml\n...\nmodels:\n    project:\n        example:\n            +required_docs: true\n```\n\nWould result in the following error when validated via a `run-operation`:\n```\nusr@home dbt-meta-testing $ dbt run-operation required_docs\nRunning with dbt=0.20.0\nEncountered an error while running operation: Compilation Error in macro required_docs (macros/required_docs.sql)\n  The following models are missing descriptions:\n   - model_2\n  The following columns are missing from the model yml:\n   - model_2.new\n  The following columns are present in the model yml, but have blank descriptions:\n   - model_1.id\n\n  \u003e in macro _evaluate_required_docs (macros/utils/required_docs/evaluate_required_docs.sql)\n  \u003e called by macro required_docs (macros/required_docs.sql)\n  \u003e called by macro required_docs (macros/required_docs.sql)\nusr@home dbt-meta-testing $\n```\n\n## Usage\nTo assert either the `+required_tests` or `+required_docs` configuration, run\nthe correpsonding macro as a `run-operation` within the dbt CLI.\n\nBy default the macro will check all models with the corresponding configuration.\nIf any model does not meet the configuration, the `run-operation` will fail\n(non-zero) and display an appropriate error message.\n\nTo assert the configuration for only a subset of the configured models (eg. new\nmodels only in a CI) pass an argument, `models`, to the macro as a space\ndelimited string of model names to use.\n\nIt's also possible to pass in the result of a `dbt ls -m \u003cselection_syntax\u003e`\ncommand, in order to make use of [dbt node selection\nsyntax](https://docs.getdbt.com/reference/node-selection/syntax). Use shell\nsubsitution in a dictionary representation.\n\nFor example, to run only changed models using dbt's Slim CI feature:\n```bash\ndbt run-operation required_tests --args \"{'models':'$(dbt list -m state:modified --state \u003cfilepath\u003e)'}\"\n```\n\nAlternatively, a space\ndelimited string of model names will work as well:\n```bash\ndbt run-operation required_tests --args \"{'models':'model1 model2 model3'}\"\n```\n\n### required_tests ([source](macros/required_tests.sql))\nValidates that models meet the `+required_tests` configurations applied in\n`dbt_project.yml`. Typically used only as a `run-operation` in a CI pipeline.\n\nUsage:\n```\ndbt run-operation required_tests [--args \"{'models': '\u003cspace_delimited_models\u003e'}\"]\n```\n\n### required_docs ([source](macros/required_tests.sql))\nValidates that models meet the `+required_docs` configurations applied in\n`dbt_project.yml`. Typically used only as a `run-operation` in a CI pipeline.\n\n\nUsage:\n```\ndbt run-operation required_docs [--args \"{'models': '\u003cspace_delimited_models\u003e'}\"]\n```\n**Note:** Run this command _after_ `dbt run`: only models that already exist in\nthe warehouse can be validated for columns that are missing from the model `.yml`.\nBy default, column names are assumed to be lower case in the DBT documentation,\nif this is not the case in your project, setting the variable\n`convert_column_names_to_lower_case` to `false` in `dbt_project.yml` will\ncompare the column names in the case they appear.\n\n## Contributions\nFeedback on this project is welcomed and encouraged. Please open an issue or\nstart a discussion if you would like to request a feature change or contribute\nto this project.\n\n## Testing\nThe integration tests for this package are located at\n[./integration_tests/tests/](integration_tests/tests/).\n\nTo run the tests locally, ensure you have the correct environment variables set\naccording to the targets in\n[./integration_tests/profiles.yml](integration_tests/profiles.yml) and use:\n```bash\ncd integration_tests\ndbt test --data\n```\n\n### Verified Data Warehouses\nThis package has been tested for the following data warehouses:\n- Snowflake\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftnightengale%2Fdbt-meta-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftnightengale%2Fdbt-meta-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftnightengale%2Fdbt-meta-testing/lists"}