@@ -856,37 +856,47 @@ def test_run_query(sushi_test_project: Project, runtime_renderer: t.Callable):
856856
857857
858858@pytest .mark .xdist_group ("dbt_manifest" )
859- def test_logging (sushi_test_project : Project , runtime_renderer : t .Callable , capsys ):
859+ def test_logging (sushi_test_project : Project , runtime_renderer : t .Callable ):
860860 context = sushi_test_project .context
861861 assert context .target
862862 engine_adapter = context .target .to_sqlmesh ().create_engine_adapter ()
863863 renderer = runtime_renderer (context , engine_adapter = engine_adapter )
864864
865865 logger = logging .getLogger ("sqlmesh.dbt.builtin" )
866866
867- # Test log with info=False (default) which should only log with debug
868- with patch .object (logger , "debug" ) as mock_debug , patch .object (logger , "info" ) as mock_info :
867+ # Test log with info=False (default), should only log to file with debug and not to console
868+ with (
869+ patch .object (logger , "debug" ) as mock_debug ,
870+ patch .object (logger , "info" ) as mock_info ,
871+ patch .object (get_console (), "log_status_update" ) as mock_console ,
872+ ):
869873 assert renderer ('{{ log("foo") }}' ) == ""
870874 mock_debug .assert_called_once ()
871875 assert "foo" in mock_debug .call_args [0 ][0 ]
872876 mock_info .assert_not_called ()
873-
874- captured = capsys .readouterr ()
875- assert "foo" not in captured .out
876-
877- # Test log with info=True, now should log with info and also print to stdout
878- with patch .object (logger , "debug" ) as mock_debug , patch .object (logger , "info" ) as mock_info :
877+ mock_console .assert_not_called ()
878+
879+ # Test log with info=True, should log to info and also call log_status_update
880+ with (
881+ patch .object (logger , "debug" ) as mock_debug ,
882+ patch .object (logger , "info" ) as mock_info ,
883+ patch .object (get_console (), "log_status_update" ) as mock_console ,
884+ ):
879885 assert renderer ('{{ log("output to be logged with info", info=true) }}' ) == ""
880886 mock_info .assert_called_once ()
881887 assert "output to be logged with info" in mock_info .call_args [0 ][0 ]
882888 mock_debug .assert_not_called ()
883-
884- captured = capsys .readouterr ()
885- assert "output to be logged with info" in captured .out
886-
887- with patch .object (logger , "debug" ) as mock_logger :
889+ mock_console .assert_called_once ()
890+ assert "output to be logged with info" in mock_console .call_args [0 ][0 ]
891+
892+ # Test print function as well, should use debug
893+ with (
894+ patch .object (logger , "debug" ) as mock_logger ,
895+ patch .object (get_console (), "log_status_update" ) as mock_console ,
896+ ):
888897 assert renderer ('{{ print("bar") }}' ) == ""
889- assert "bar" in mock_logger .call_args [0 ][0 ]
898+ assert "bar" in mock_logger .call_args [0 ][0 ]
899+ mock_console .assert_not_called ()
890900
891901
892902@pytest .mark .xdist_group ("dbt_manifest" )
0 commit comments