@@ -184,11 +184,35 @@ def write_config(params: WriteConfigParams) -> dict[str, any]:
184184 # the client provided a config path but it doesn't exist
185185 create_empty_pyproject_toml (cfg_file )
186186
187+ # Handle both dict and object access for config
188+ def get_config_value (key : str , default : str = "" ) -> str :
189+ if isinstance (cfg , dict ):
190+ return cfg .get (key , default )
191+ return getattr (cfg , key , default )
192+
193+ tests_root = get_config_value ("tests_root" , "" )
194+ # Validate tests_root directory exists if provided
195+ if tests_root :
196+ # Resolve path relative to config file directory or current working directory
197+ if cfg_file :
198+ base_dir = cfg_file .parent
199+ else :
200+ base_dir = Path .cwd ()
201+ tests_root_path = (base_dir / tests_root ).resolve ()
202+ if not tests_root_path .exists () or not tests_root_path .is_dir ():
203+ return {
204+ "status" : "error" ,
205+ "message" : f"Invalid 'tests_root': directory does not exist at { tests_root_path } " ,
206+ "field_errors" : {
207+ "tests_root" : f"Directory does not exist at { tests_root_path } " ,
208+ },
209+ }
210+
187211 setup_info = VsCodeSetupInfo (
188- module_root = getattr ( cfg , "module_root" , "" ),
189- tests_root = getattr ( cfg , " tests_root" , "" ) ,
190- test_framework = getattr ( cfg , "test_framework" , "pytest" ),
191- formatter = get_formatter_cmds (getattr ( cfg , "formatter_cmds" , "disabled" )),
212+ module_root = get_config_value ( "module_root" , "" ),
213+ tests_root = tests_root ,
214+ test_framework = get_config_value ( "test_framework" , "pytest" ),
215+ formatter = get_formatter_cmds (get_config_value ( "formatter_cmds" , "disabled" )),
192216 )
193217
194218 devnull_writer = open (os .devnull , "w" ) # noqa
0 commit comments