Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using sql in unit testing fixtures #9873

Merged
merged 9 commits into from
Apr 17, 2024
Merged

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Apr 8, 2024

resolves #9405

Problem

In some cases there might be difficulties in getting csv or dictionary fixtures to work correctly for unit testing, so we want to allow the use of SQL fixtures.

Solution

This allows setting SQL in the unit test definition or in fixture files. At the current time it requires all columns to be specified.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

@gshank gshank requested a review from a team as a code owner April 8, 2024 13:46
@cla-bot cla-bot bot added the cla:yes label Apr 8, 2024
Copy link

codecov bot commented Apr 8, 2024

Codecov Report

Attention: Patch coverage is 96.55172% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 88.08%. Comparing base (b945d17) to head (ae37a7b).
Report is 9 commits behind head on main.

Files Patch % Lines
core/dbt/parser/unit_tests.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9873      +/-   ##
==========================================
+ Coverage   88.06%   88.08%   +0.02%     
==========================================
  Files         178      178              
  Lines       22457    22480      +23     
==========================================
+ Hits        19776    19802      +26     
+ Misses       2681     2678       -3     
Flag Coverage Δ
integration 85.45% <96.55%> (+0.03%) ⬆️
unit 61.83% <17.24%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gshank gshank added the artifact_minor_upgrade To bypass the CI check by confirming that the change is not breaking label Apr 9, 2024
Copy link
Contributor

@graciegoheen graciegoheen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this out, and looks good to me!

@gshank gshank merged commit 86b349f into main Apr 17, 2024
62 checks passed
@gshank gshank deleted the unit_testing_sql_format branch April 17, 2024 00:17
matthewshaver added a commit to dbt-labs/docs.getdbt.com that referenced this pull request Apr 17, 2024
## What are you changing in this pull request and why?
<!---
Describe your changes and why you're making them. If related to an open 
issue or a pull request on dbt Core, then link to them here! 

To learn more about the writing conventions used in the dbt Labs docs,
see the [Content style
guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md).
-->

Closes #5289

Coming soon (see core PR
[here](dbt-labs/dbt-core#9873)) we are
introducing a new format for defining mock data for unit tests -
`format: sql`.

This PR adds documentation for that new format.

## Checklist
<!--
Uncomment when publishing docs for a prerelease version of dbt:
- [ ] Add versioning components, as described in [Versioning
Docs](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#versioning-entire-pages)
- [ ] Add a note to the prerelease version [Migration
Guide](https://github.com/dbt-labs/docs.getdbt.com/tree/current/website/docs/docs/dbt-versions/core-upgrade)
-->
- [ ] Review the [Content style
guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md)
so my content adheres to these guidelines.
- [ ] For [docs
versioning](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#about-versioning),
review how to [version a whole
page](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#adding-a-new-version)
and [version a block of
content](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#versioning-blocks-of-content).
- [ ] Add a checklist item for anything that needs to happen before this
PR is merged, such as "needs technical review" or "change base branch."

Adding or removing pages (delete if not applicable):
- [ ] Add/remove page in `website/sidebars.js`
- [ ] Provide a unique filename for new pages
- [ ] Add an entry for deleted pages in `website/vercel.json`
- [ ] Run link testing locally with `npm run build` to update the links
that point to deleted pages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
artifact_minor_upgrade To bypass the CI check by confirming that the change is not breaking cla:yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-3567] [Feature] unit testing support format: sql
3 participants