@@ -854,13 +854,40 @@ def test_logging(sushi_test_project: Project, runtime_renderer: t.Callable):
854854 renderer = runtime_renderer (context , engine_adapter = engine_adapter )
855855
856856 logger = logging .getLogger ("sqlmesh.dbt.builtin" )
857- with patch .object (logger , "debug" ) as mock_logger :
858- assert renderer ('{{ log("foo") }}' ) == ""
859- assert "foo" in mock_logger .call_args [0 ][0 ]
860857
861- with patch .object (logger , "debug" ) as mock_logger :
858+ # Test log with info=False (default), should only log to file with debug and not to console
859+ with (
860+ patch .object (logger , "debug" ) as mock_debug ,
861+ patch .object (logger , "info" ) as mock_info ,
862+ patch .object (get_console (), "log_status_update" ) as mock_console ,
863+ ):
864+ assert renderer ('{{ log("foo") }}' ) == ""
865+ mock_debug .assert_called_once ()
866+ assert "foo" in mock_debug .call_args [0 ][0 ]
867+ mock_info .assert_not_called ()
868+ mock_console .assert_not_called ()
869+
870+ # Test log with info=True, should log to info and also call log_status_update
871+ with (
872+ patch .object (logger , "debug" ) as mock_debug ,
873+ patch .object (logger , "info" ) as mock_info ,
874+ patch .object (get_console (), "log_status_update" ) as mock_console ,
875+ ):
876+ assert renderer ('{{ log("output to be logged with info", info=true) }}' ) == ""
877+ mock_info .assert_called_once ()
878+ assert "output to be logged with info" in mock_info .call_args [0 ][0 ]
879+ mock_debug .assert_not_called ()
880+ mock_console .assert_called_once ()
881+ assert "output to be logged with info" in mock_console .call_args [0 ][0 ]
882+
883+ # Test print function as well, should use debug
884+ with (
885+ patch .object (logger , "debug" ) as mock_logger ,
886+ patch .object (get_console (), "log_status_update" ) as mock_console ,
887+ ):
862888 assert renderer ('{{ print("bar") }}' ) == ""
863- assert "bar" in mock_logger .call_args [0 ][0 ]
889+ assert "bar" in mock_logger .call_args [0 ][0 ]
890+ mock_console .assert_not_called ()
864891
865892
866893@pytest .mark .xdist_group ("dbt_manifest" )
0 commit comments