22
22
from astroid import modutils
23
23
from astroid .const import PY310_PLUS
24
24
from astroid .interpreter ._import import spec
25
+ from astroid .util import augmented_sys_path
25
26
26
27
from . import resources
27
28
@@ -178,21 +179,19 @@ def test_import_symlink_with_source_outside_of_path(self) -> None:
178
179
def test_modpath_from_file_path_order (self ) -> None :
179
180
"""Test for ordering of paths.
180
181
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
182
183
2. Create a module file in sub directory of tmp directory
183
184
3. If the sub directory is passed as additional directory, module name
184
185
should be relative to the subdirectory since additional directory has
185
186
higher precedence."""
186
- orig_path = sys .path .copy ()
187
187
with tempfile .TemporaryDirectory () as tmp_dir :
188
- try :
188
+ with augmented_sys_path ([ tmp_dir ]) :
189
189
mod_name = "module"
190
190
sub_dirname = "subdir"
191
191
sub_dir = tmp_dir + "/" + sub_dirname
192
192
os .mkdir (sub_dir )
193
193
module_file = f"{ sub_dir } /{ mod_name } .py"
194
194
195
- sys .path .insert (0 , str (tmp_dir ))
196
195
with open (module_file , "w+" , encoding = "utf-8" ):
197
196
pass
198
197
@@ -207,8 +206,6 @@ def test_modpath_from_file_path_order(self) -> None:
207
206
modutils .modpath_from_file (f"{ sub_dir } /{ mod_name } .py" , [sub_dir ]),
208
207
[mod_name ],
209
208
)
210
- finally :
211
- sys .path [:] = orig_path
212
209
213
210
def test_import_symlink_both_outside_of_path (self ) -> None :
214
211
with tempfile .NamedTemporaryFile () as tmpfile :
0 commit comments