@@ -847,37 +847,47 @@ def test_run_query(sushi_test_project: Project, runtime_renderer: t.Callable):
847847
848848
849849@pytest .mark .xdist_group ("dbt_manifest" )
850- def test_logging (sushi_test_project : Project , runtime_renderer : t .Callable , capsys ):
850+ def test_logging (sushi_test_project : Project , runtime_renderer : t .Callable ):
851851 context = sushi_test_project .context
852852 assert context .target
853853 engine_adapter = context .target .to_sqlmesh ().create_engine_adapter ()
854854 renderer = runtime_renderer (context , engine_adapter = engine_adapter )
855855
856856 logger = logging .getLogger ("sqlmesh.dbt.builtin" )
857857
858- # Test log with info=False (default) which should only log with debug
859- with patch .object (logger , "debug" ) as mock_debug , patch .object (logger , "info" ) as mock_info :
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+ ):
860864 assert renderer ('{{ log("foo") }}' ) == ""
861865 mock_debug .assert_called_once ()
862866 assert "foo" in mock_debug .call_args [0 ][0 ]
863867 mock_info .assert_not_called ()
864-
865- captured = capsys .readouterr ()
866- assert "foo" not in captured .out
867-
868- # Test log with info=True, now should log with info and also print to stdout
869- with patch .object (logger , "debug" ) as mock_debug , patch .object (logger , "info" ) as mock_info :
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+ ):
870876 assert renderer ('{{ log("output to be logged with info", info=true) }}' ) == ""
871877 mock_info .assert_called_once ()
872878 assert "output to be logged with info" in mock_info .call_args [0 ][0 ]
873879 mock_debug .assert_not_called ()
874-
875- captured = capsys .readouterr ()
876- assert "output to be logged with info" in captured .out
877-
878- with patch .object (logger , "debug" ) as mock_logger :
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+ ):
879888 assert renderer ('{{ print("bar") }}' ) == ""
880- 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 ()
881891
882892
883893@pytest .mark .xdist_group ("dbt_manifest" )
0 commit comments