-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add testing #22
Merged
Merged
Add testing #22
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c6b517d
Add working script to run macro
JCZuurmond b3b0a0a
Add comment about adapters
JCZuurmond 5bb9728
Try using a project instead of runtime config
JCZuurmond 4e31232
Remove spark credentials and Project
JCZuurmond 37aa6e6
Use connection from soda spark
JCZuurmond 69ed207
Add test requirements
JCZuurmond 236286d
Add pytest ini
JCZuurmond d72ebf2
Move everything into pytest fixtures
JCZuurmond 18170a1
Copy connection
JCZuurmond 25e5806
Remove pytest-dbt-core code
JCZuurmond 409d827
Add pytest dbt core as test requirement
JCZuurmond 56c848a
Add workflow for testing
JCZuurmond 1560e5e
Bump pytest dbt core version
JCZuurmond 3014264
Add profile to dbt project
JCZuurmond 153708b
Add profiles
JCZuurmond f9b0db7
Add profiles dir when running pytest
JCZuurmond 52307bb
Remove redundant from future import annotations
JCZuurmond cb447a2
Bump pytest-dbt-core version
JCZuurmond 8b7eb8f
Change version
JCZuurmond 6dfd9f7
Add pyspark dependency
JCZuurmond 91b6bb1
Change pyspark dependency to dbt-spark session
JCZuurmond 30112b0
Change required by to dbt-spark
JCZuurmond 59f2139
Add test docstring
JCZuurmond 74482a7
Make test less strict
JCZuurmond df29346
Create and delete table with fixture
JCZuurmond ffe50cb
Fix typo
JCZuurmond 8b13fda
Add section about testing to the documentation
JCZuurmond 29e88d6
Move test macros into tests/unit
JCZuurmond ee25a3e
Run unit tests only in Github action
JCZuurmond bbc7923
Merge dev and test requirements
JCZuurmond d380607
Move conftest into functional
JCZuurmond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
sudo apt-get install libsasl2-dev | ||
python -m pip install --upgrade pip | ||
python -m pip install -r test-requirements.txt | ||
|
||
- name: Run pytest | ||
shell: bash | ||
run: DBT_PROFILES_DIR=$PWD pytest tests/ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
name: 'spark_utils' | ||
profile: 'sparkutils' | ||
version: '0.3.0' | ||
config-version: 2 | ||
require-dbt-version: [">=1.2.0", "<2.0.0"] | ||
macro-paths: ["macros"] | ||
macro-paths: ["macros"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sparkutils: | ||
target: test | ||
outputs: | ||
test: | ||
type: spark | ||
method: session | ||
schema: test | ||
host: NA # not used, but required by `dbt-spark` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pytest~=6.2.5 | ||
pytest-spark~=0.6.0 | ||
JCZuurmond marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pytest-dbt-core~=0.1.0 | ||
dbt-spark[session]~=1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import uuid | ||
|
||
import pytest | ||
from dbt.clients.jinja import MacroGenerator | ||
from pyspark.sql import SparkSession | ||
|
||
|
||
@pytest.fixture | ||
def simple_table(spark_session: SparkSession) -> str: | ||
JCZuurmond marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Create and delete a simple table used for testing.""" | ||
table_name = f"default.table_{uuid.uuid4()}".replace("-", "_") | ||
spark_session.sql(f"CREATE TABLE {table_name} (id int) USING parquet") | ||
yield table_name | ||
spark_session.sql(f"DROP TABLE IF EXISTS {table_name}") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"macro_generator", ["macro.spark_utils.get_tables"], indirect=True | ||
) | ||
def test_create_table( | ||
macro_generator: MacroGenerator, simple_table: str | ||
) -> None: | ||
"""The `get_tables` macro should return the created table.""" | ||
tables = macro_generator() | ||
assert simple_table in tables | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see - this tries to run
tests/functional/test_utils.py
as well (added in #25), which has other requirements (specified indev-requirements.txt
).Options:
python -m pip install -r dev-requirements.txt
into the "Install dependencies" step above—or better yet, unifydev-requirements
+test-requirements
into a single file—and try running the tests with--profile session
. I imagine that a few may fail (as indbt-spark
), but the rest should succeed, and we can mark the failing ones to skip on the "session" profile.tests/functional
for the tests using thedbt-core
functional-testing framework, andtests/unit
for the tests using thepytest-dbt-core
unit-testing framework. Have clearly separate READMEs and files used by each: separate requirements, separate profile setup, all that jazz.What do you think? I lean toward option 2, "separate" — and then
tests/unit
could be a clear, self-contained, and real-world demonstration of the potential ofpytest-dbt-core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to option 2, "separate" (especially different folders
tests/unit
vs.tests/functional
).Separate folders won't undermine the functionality at all, and it will make the delineations between different frameworks more clear.
Side note: I don't see a problem with them sharing a single
dev-requirements.txt
though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the
test_macros.py
in aunit
subfolder. And, I merged thetest-requirements.txt
into thedev-requirements.txt
. I think it is confusing to have atest-requirements.txt
that does not contain all dependencies for the functional tests.I had to move the
conftest.py
into thefunctional
subdirectory because it was interfering with the unit tests.