1414from sqlmesh .utils .yaml import load as yaml_load
1515
1616if t .TYPE_CHECKING :
17- from sqlmesh .core .loader import Loader
17+ from sqlmesh .core .config . loader import C
1818
1919
2020class ModelTestMetadata (PydanticModel ):
@@ -32,7 +32,8 @@ def __hash__(self) -> int:
3232
3333def load_model_test_file (
3434 path : pathlib .Path ,
35- get_variables : t .Callable [[t .Optional [str ]], t .Dict [str , str ]],
35+ config : C ,
36+ get_variables : t .Callable [[t .Optional [C ], t .Optional [str ]], t .Dict [str , str ]],
3637) -> dict [str , ModelTestMetadata ]:
3738 """Load a single model test file.
3839
@@ -43,7 +44,7 @@ def load_model_test_file(
4344 A list of ModelTestMetadata named tuples.
4445 """
4546 model_test_metadata = {}
46- contents = yaml_load (path , get_variables = get_variables )
47+ contents = yaml_load (path , config = config , get_variables = get_variables )
4748
4849 for test_name , value in contents .items ():
4950 model_test_metadata [test_name ] = ModelTestMetadata (
@@ -54,8 +55,8 @@ def load_model_test_file(
5455
5556def discover_model_tests (
5657 path : pathlib .Path ,
57- get_variables : t . Callable [[ t . Optional [ str ]], t . Dict [ str , str ]] ,
58- ignore_patterns : list [ str ] | None = None ,
58+ config : C ,
59+ get_variables : t . Callable [[ t . Optional [ C ], t . Optional [ str ]], t . Dict [ str , str ]] ,
5960) -> Iterator [ModelTestMetadata ]:
6061 """Discover model tests.
6162
@@ -74,12 +75,12 @@ def discover_model_tests(
7475 search_path .glob ("**/test*.yaml" ),
7576 search_path .glob ("**/test*.yml" ),
7677 ):
77- for ignore_pattern in ignore_patterns or []:
78+ for ignore_pattern in config . ignore_patterns or []:
7879 if yaml_file .match (ignore_pattern ):
7980 break
8081 else :
8182 for model_test_metadata in load_model_test_file (
82- yaml_file , get_variables = get_variables
83+ yaml_file , config = config , get_variables = get_variables
8384 ).values ():
8485 yield model_test_metadata
8586
@@ -105,7 +106,8 @@ def filter_tests_by_patterns(
105106
106107
107108def load_model_tests (
108- loaders : list [Loader ],
109+ configs : t .Dict [pathlib .Path , C ],
110+ get_variables : t .Callable [[t .Optional [C ], t .Optional [str ]], t .Dict [str , str ]],
109111 tests : t .Optional [t .List [str ]] = None ,
110112 patterns : list [str ] | None = None ,
111113) -> list [ModelTestMetadata ]:
@@ -123,23 +125,22 @@ def load_model_tests(
123125 filename , test_name = test .split ("::" , maxsplit = 1 ) if "::" in test else (test , "" )
124126
125127 test_file = load_model_test_file (
126- pathlib .Path (filename ), get_variables = loaders [0 ]._get_variables
128+ pathlib .Path (filename ),
129+ config = next (iter (configs .values ())),
130+ get_variables = get_variables ,
127131 )
128132 if test_name :
129133 test_meta .append (test_file [test_name ])
130134 else :
131135 test_meta .extend (test_file .values ())
132136 else :
133- for loader in loaders :
137+ for path , config in configs . items () :
134138 test_meta .extend (
135- [
136- meta
137- for meta in discover_model_tests (
138- pathlib .Path (loader .config_path / c .TESTS ),
139- ignore_patterns = loader .config .ignore_patterns , # type: ignore
140- get_variables = loader ._get_variables ,
141- )
142- ]
139+ discover_model_tests (
140+ pathlib .Path (path / c .TESTS ),
141+ config = config ,
142+ get_variables = get_variables ,
143+ )
143144 )
144145
145146 if patterns :
0 commit comments