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

Python model logging #1115

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
37 changes: 37 additions & 0 deletions tests/functional/adapter/python_model_tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from dbt.tests.util import run_dbt
import pytest


MODEL__LOGGING = """
import logging

import snowflake.snowpark as snowpark
import snowflake.snowpark.functions as f
from snowflake.snowpark.functions import *


logger = logging.getLogger("dbt_logger")
logger.info("******Inside Logging module.******")


def model(dbt, session: snowpark.Session):
# To use: GRANT MODIFY SESSION LOG LEVEL ON ACCOUNT TO ROLE <DBT_ROLE>;
dbt.config(pre_hook = 'ALTER SESSION SET LOG_LEVEL=INFO;')
logger.info("******Logging start.******")
df=session.sql(f"select current_user() as session_user, current_role() as session_role")
logger.info("******Logging End.******")
return df
"""


class TestPythonModelLogging:
"""
This test case addresses bug report https://github.com/dbt-labs/dbt-snowflake/issues/846
"""

@pytest.fixture(scope="class")
def models(self):
return {"logging_model.py": MODEL__LOGGING}

def test_logging(self, project):
run_dbt(["run"])
Loading