Giter Site home page Giter Site logo

godatadriven / pytest-dbt-core Goto Github PK

View Code? Open in Web Editor NEW
53.0 4.0 2.0 71 KB

Pytest plugin for dbt core

Home Page: https://pytest-dbt-core.readthedocs.io/en/latest/

License: Apache License 2.0

Python 100.00%
dbt pytest pytest-extension test testing dbt-tests dbt-macros

pytest-dbt-core's People

Contributors

constantinoschillebeeckx avatar dependabot[bot] avatar jczuurmond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pytest-dbt-core's Issues

[Feature] Support dbt 'is_incremental' in pytest-dbt-core

Is this your first time opening an issue?

Describe the Feature

dbt adds the 'this' somehow in the is_incremental macro:
https://github.com/dbt-labs/dbt-core/blob/main/core/dbt/include/global_project/macros/materializations/models/incremental/is_incremental.sql
is_incremental.sql

{% macro is_incremental() %}
{#-- do not run introspective queries in parsing #}
{% if not execute %}
{{ return(False) }}

Describe alternatives you've considered

I would like to test the following macro that uses 'is_incremental' and 'this' argument

{% macro get_table_max_id(where_clause = '', id_column = '"id"') %}
    {% if is_incremental() %}
        {% set max_id_query %}
        select coalesce(max({{ id_column }}), 0) from {{ this }}
        {{ where_clause }}
        {% endset %}
        {% set max_id_res = run_query(max_id_query) %}
    {%endif%}
    {{ return(max_id) }}
{% endmacro %}

following error:
def raise_compiler_error(msg, node=None) -> NoReturn:

  raise CompilationException(msg, node)

E dbt.exceptions.CompilationException: Compilation Error in macro is_incremental (macros/materializations/models/incremental/is_incremental.sql)
E 'this' is undefined
E
E > in macro get_table_max_id (macros/unioner.sql)
E > called by macro test_table_max_id (macros/test_macro.sql)
E > called by macro is_incremental (macros/materializations/models/incremental/is_incremental.sql)

Who will this benefit?

All dbt users since is_incremental is very popular

Are you interested in contributing this feature?

No response

Anything else?

No response

[Feature] Add more test examples to docs

Is this your first time opening an issue?

Describe the Feature

Add more examples to the docs, maybe as a separate page.

Describe alternatives you've considered

NA

Who will this benefit?

Users, the examples should help them get started quickly

Are you interested in contributing this feature?

yes

Anything else?

No response

[Feature] Run example tests from docs

Is this your first time opening an issue?

Describe the Feature

The docs contain example tests, we should verify that those pass.

Note:

  • The examples rely on macros. Where do we keep those? These should be stored in a place so that the tests can use them.

Describe alternatives you've considered

NA

Who will this benefit?

Me, as package maintainer I want to make sure that the examples in docs are accurate

Are you interested in contributing this feature?

yes

Anything else?

No response

[Feature] Run in DBT Cloud

Is this your first time opening an issue?

Describe the Feature

Lots of my colleagues uses the DBT Cloud IDE. It lowers the entry barrier for anyone not experience with IDEs, git, etc. With that in mind, I would like them to also have the possibility to write unit tests and run the tests in that environment.

Describe alternatives you've considered

Running tests in CI pipeline, but this creates a very slow feedback loop.

Who will this benefit?

Any DBT developer using DBT Cloud IDE

Are you interested in contributing this feature?

Yes

Anything else?

I have now clue if this is even remotely possible. Does that DBT cloud runtime include Pytest? Is it possible to create a DBT package which pulls in additional packages from pypi?

[Feature] Flag to set the target

Is this your first time opening an issue?

Describe the Feature

Add a flag to set the target.

Describe alternatives you've considered

Do not set a specific target, use the default target

Who will this benefit?

Everyone who does not want to use the default target

Are you interested in contributing this feature?

yes

Anything else?

Add flag to plugin:

# src/pytest_dbt_core/plugin.py
...
def pytest_addoption(...):
    ....
    
    parser.addoption(
        "--dbt-target",
        help="Which target to load for the given profile",
        type="string",
    )

And test in the example project in tests/

[Feature] Add examples for mocking macros

Is this your first time opening an issue?

Describe the Feature

We are working on a use case where the macro internally maps to some classes. To perform the testing efficiently, classes need to be mocked instead of class functionality being used.
With macros directly pytest mocking cannot be used, some examples need to be added to showcase how to mock in the case of macros.

Describe alternatives you've considered

No response

Who will this benefit?

No response

Are you interested in contributing this feature?

No response

Anything else?

No response

[Feature] Unit testing models

Is this your first time opening an issue?

Describe the Feature

Support unit testing models. Most likely we need another fixture to fetch a model, then similar to a macro, we use that fixture in a test.

To consider:

  • models usually contain references to other models or sources: ref and source. How do we handle this? Could we for example mock them? If so, can we share mocks across tests.

Describe alternatives you've considered

Not unit testing models, stick to unit testing macros. You can put the complex SQL - or all SQL - in (modular) macros, then test those. This is not user friendly though.

Who will this benefit?

Those who want to test models, not just macros

Are you interested in contributing this feature?

Yes

Anything else?

See discussion on this topic in the dbt-core repo

[Feature] Add quickstart guide to docs

Is this your first time opening an issue?

Describe the Feature

Add a quickstart guide to the docs

Describe alternatives you've considered

NA

Who will this benefit?

Package users, the quickstart should help them get started quickly.

Are you interested in contributing this feature?

yes

Anything else?

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.