2222from astroid import modutils
2323from astroid .const import PY310_PLUS
2424from astroid .interpreter ._import import spec
25+ from astroid .util import augmented_sys_path
2526
2627from . import resources
2728
@@ -178,21 +179,19 @@ def test_import_symlink_with_source_outside_of_path(self) -> None:
178179 def test_modpath_from_file_path_order (self ) -> None :
179180 """Test for ordering of paths.
180181 The test does the following:
181- 1. Add a tmp directory to beginning of sys.path
182+ 1. Add a tmp directory to beginning of sys.path via augmented_sys_path
182183 2. Create a module file in sub directory of tmp directory
183184 3. If the sub directory is passed as additional directory, module name
184185 should be relative to the subdirectory since additional directory has
185186 higher precedence."""
186- orig_path = sys .path .copy ()
187187 with tempfile .TemporaryDirectory () as tmp_dir :
188- try :
188+ with augmented_sys_path ([ tmp_dir ]) :
189189 mod_name = "module"
190190 sub_dirname = "subdir"
191191 sub_dir = tmp_dir + "/" + sub_dirname
192192 os .mkdir (sub_dir )
193193 module_file = f"{ sub_dir } /{ mod_name } .py"
194194
195- sys .path .insert (0 , str (tmp_dir ))
196195 with open (module_file , "w+" , encoding = "utf-8" ):
197196 pass
198197
@@ -207,8 +206,6 @@ def test_modpath_from_file_path_order(self) -> None:
207206 modutils .modpath_from_file (f"{ sub_dir } /{ mod_name } .py" , [sub_dir ]),
208207 [mod_name ],
209208 )
210- finally :
211- sys .path [:] = orig_path
212209
213210 def test_import_symlink_both_outside_of_path (self ) -> None :
214211 with tempfile .NamedTemporaryFile () as tmpfile :
0 commit comments