@@ -672,36 +672,26 @@ def test_positional_follows_kwargs(macro_evaluator):
672672
673673
674674def test_macro_parameter_resolution (macro_evaluator ):
675- with pytest .raises (MacroEvalError ) as e :
675+ with pytest .raises (MacroEvalError , match = ".*missing a required argument: 'pos_only'" ) :
676676 macro_evaluator .evaluate (parse_one ("@test_arg_resolution()" ))
677- assert str (e .value .__cause__ ) == "missing a required argument: 'pos_only'"
678677
679- with pytest .raises (MacroEvalError ) as e :
678+ with pytest .raises (MacroEvalError , match = ".*missing a required argument: 'pos_only'" ) :
680679 macro_evaluator .evaluate (parse_one ("@test_arg_resolution(a1 := 1)" ))
681- assert str (e .value .__cause__ ) == "missing a required argument: 'pos_only'"
682680
683- with pytest .raises (MacroEvalError ) as e :
681+ with pytest .raises (MacroEvalError , match = ".*missing a required argument: 'a1'" ) :
684682 macro_evaluator .evaluate (parse_one ("@test_arg_resolution(1)" ))
685- assert str (e .value .__cause__ ) == "missing a required argument: 'a1'"
686683
687- with pytest .raises (MacroEvalError ) as e :
684+ with pytest .raises (MacroEvalError , match = ".*missing a required argument: 'a1'" ) :
688685 macro_evaluator .evaluate (parse_one ("@test_arg_resolution(1, a2 := 2)" ))
689- assert str (e .value .__cause__ ) == "missing a required argument: 'a1'"
690686
691- with pytest .raises (MacroEvalError ) as e :
687+ with pytest .raises (
688+ MacroEvalError ,
689+ match = ".*'pos_only' parameter is positional only, but was passed as a keyword|.*missing a required positional-only argument: 'pos_only'|.*missing a required argument: 'a1'" ,
690+ ):
692691 macro_evaluator .evaluate (parse_one ("@test_arg_resolution(pos_only := 1)" ))
693692
694- # The CI was failing for Python 3.12 with the latter message, but other versions fail
695- # with the former one. This ensures we capture both.
696- assert str (e .value .__cause__ ) in (
697- "'pos_only' parameter is positional only, but was passed as a keyword" ,
698- "missing a required positional-only argument: 'pos_only'" ,
699- "missing a required argument: 'a1'" ,
700- )
701-
702- with pytest .raises (MacroEvalError ) as e :
693+ with pytest .raises (MacroEvalError , match = ".*too many positional arguments" ):
703694 macro_evaluator .evaluate (parse_one ("@test_arg_resolution(1, 2, 3)" ))
704- assert str (e .value .__cause__ ) == "too many positional arguments"
705695
706696
707697def test_macro_metadata_flag ():
@@ -808,28 +798,25 @@ def test_deduplicate(assert_exp_eq, dialect, sql, expected_sql):
808798
809799def test_deduplicate_error_handling (macro_evaluator ):
810800 # Test error handling: non-list partition_by
811- with pytest .raises (SQLMeshError ) as e :
801+ with pytest .raises (
802+ SQLMeshError ,
803+ match = "partition_by must be a list of columns: \\ [<column>, cast\\ (<column> as <type>\\ )\\ ]" ,
804+ ):
812805 macro_evaluator .evaluate (parse_one ("@deduplicate(my_table, user_id, ['timestamp DESC'])" ))
813- assert (
814- str (e .value .__cause__ )
815- == "partition_by must be a list of columns: [<column>, cast(<column> as <type>)]"
816- )
817806
818807 # Test error handling: non-list order_by
819- with pytest .raises (SQLMeshError ) as e :
808+ with pytest .raises (
809+ SQLMeshError ,
810+ match = "order_by must be a list of strings, optional - nulls ordering: \\ ['<column> <asc|desc> nulls <first|last>'\\ ]" ,
811+ ):
820812 macro_evaluator .evaluate (parse_one ("@deduplicate(my_table, [user_id], 'timestamp DESC')" ))
821- assert (
822- str (e .value .__cause__ )
823- == "order_by must be a list of strings, optional - nulls ordering: ['<column> <asc|desc> nulls <first|last>']"
824- )
825813
826814 # Test error handling: empty order_by
827- with pytest .raises (SQLMeshError ) as e :
815+ with pytest .raises (
816+ SQLMeshError ,
817+ match = "order_by must be a list of strings, optional - nulls ordering: \\ ['<column> <asc|desc> nulls <first|last>'\\ ]" ,
818+ ):
828819 macro_evaluator .evaluate (parse_one ("@deduplicate(my_table, [user_id], [])" ))
829- assert (
830- str (e .value .__cause__ )
831- == "order_by must be a list of strings, optional - nulls ordering: ['<column> <asc|desc> nulls <first|last>']"
832- )
833820
834821
835822@pytest .mark .parametrize (
@@ -991,34 +978,32 @@ def test_date_spine(assert_exp_eq, dialect, date_part):
991978
992979def test_date_spine_error_handling (macro_evaluator ):
993980 # Test error handling: invalid datepart
994- with pytest .raises (SQLMeshError ) as e :
981+ with pytest .raises (
982+ MacroEvalError ,
983+ match = ".*Invalid datepart 'invalid'. Expected: 'day', 'week', 'month', 'quarter', or 'year'" ,
984+ ):
995985 macro_evaluator .evaluate (parse_one ("@date_spine('invalid', '2022-01-01', '2024-12-31')" ))
996- assert (
997- str (e .value .__cause__ )
998- == "Invalid datepart 'invalid'. Expected: 'day', 'week', 'month', 'quarter', or 'year'"
999- )
1000986
1001987 # Test error handling: invalid start_date format
1002- with pytest .raises (SQLMeshError ) as e :
988+ with pytest .raises (
989+ MacroEvalError ,
990+ match = ".*Invalid date format - start_date and end_date must be in format: YYYY-MM-DD" ,
991+ ):
1003992 macro_evaluator .evaluate (parse_one ("@date_spine('day', '2022/01/01', '2024-12-31')" ))
1004- assert str (e .value .__cause__ ).startswith (
1005- "Invalid date format - start_date and end_date must be in format: YYYY-MM-DD"
1006- )
1007993
1008994 # Test error handling: invalid end_date format
1009- with pytest .raises (SQLMeshError ) as e :
995+ with pytest .raises (
996+ MacroEvalError ,
997+ match = ".*Invalid date format - start_date and end_date must be in format: YYYY-MM-DD" ,
998+ ):
1010999 macro_evaluator .evaluate (parse_one ("@date_spine('day', '2022-01-01', '2024/12/31')" ))
1011- assert str (e .value .__cause__ ).startswith (
1012- "Invalid date format - start_date and end_date must be in format: YYYY-MM-DD"
1013- )
10141000
10151001 # Test error handling: start_date after end_date
1016- with pytest .raises (SQLMeshError ) as e :
1002+ with pytest .raises (
1003+ MacroEvalError ,
1004+ match = ".*Invalid date range - start_date '2024-12-31' is after end_date '2022-01-01'." ,
1005+ ):
10171006 macro_evaluator .evaluate (parse_one ("@date_spine('day', '2024-12-31', '2022-01-01')" ))
1018- assert (
1019- str (e .value .__cause__ )
1020- == "Invalid date range - start_date '2024-12-31' is after end_date '2022-01-01'."
1021- )
10221007
10231008
10241009def test_macro_union (assert_exp_eq , macro_evaluator : MacroEvaluator ):
@@ -1044,11 +1029,9 @@ def test_resolve_template_literal():
10441029 # Creating
10451030 # This macro can work during creating / evaluating but only if @this_model is present in the context
10461031 evaluator = MacroEvaluator (runtime_stage = RuntimeStage .CREATING )
1047- with pytest .raises (SQLMeshError ) as e :
1032+ with pytest .raises (MacroEvalError , match = ".*this_model must be present" ) :
10481033 evaluator .transform (parsed_sql )
10491034
1050- assert "this_model must be present" in str (e .value .__cause__ )
1051-
10521035 evaluator .locals .update (
10531036 {"this_model" : exp .to_table ("test_catalog.sqlmesh__test.test__test_model__2517971505" )}
10541037 )
0 commit comments