Skip to content

Refactor pytest unit tests to dbt unit tests #269

Refactor pytest unit tests to dbt unit tests

Refactor pytest unit tests to dbt unit tests #269

name: Run Unit Tests on Pull Request
on: [pull_request_target,workflow_dispatch]
env:
BIGQUERY_PROJECT: ${{ secrets.BIGQUERY_PROJECT }}
BIGQUERY_PROPERTY_ID: ${{ secrets.BIGQUERY_PROPERTY_ID }}
BIGQUERY_DATASET: ${{ secrets.BIGQUERY_DATASET }}
BIGQUERY_KEYFILE: ./unit_tests/dbt-service-account.json
jobs:
pytest_run_all:
name: Pytest Run All
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./unit_tests
steps:
- name: Check out
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-python@v1
with:
python-version: "3.11.x"
- name: Authenticate using service account
run: 'echo "$KEYFILE" > ./dbt-service-account.json'
shell: bash
env:
KEYFILE: ${{secrets.GCP_BIGQUERY_USER_KEYFILE}}
- name: Install dependencies
run: |
pip install dbt-core
pip install dbt-bigquery
pip install pytest
- name: Run tests
run: python -m pytest .
run_dbt_unit_tests:
name: Run dbt Unit Tests
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-python@v1
with:
python-version: "3.11.x"
- name: Authenticate using service account
run: 'echo "$KEYFILE" > ./unit_tests/dbt-service-account.json'
shell: bash
env:
KEYFILE: ${{ secrets.GCP_BIGQUERY_USER_KEYFILE }}
- name: Install dbt
run: |
pip install dbt-core
pip install dbt-bigquery
dbt deps
- name: Materialize necessary dbt resources
run: |
dbt seed -f
dbt run -s +test_type:unit -f --empty
- name: Run dbt unit tests
run: dbt test -s test_type:unit