@@ -2050,7 +2050,8 @@ def test_existing_fake_file_raises(self):
20502050
20512051 @contextlib .contextmanager
20522052 def create_real_paths (self ):
2053- real_dir_root = os .path .join (tempfile .gettempdir (), "root" )
2053+ temp_directory = tempfile .mkdtemp ()
2054+ real_dir_root = os .path .join (temp_directory , "root" )
20542055 try :
20552056 for dir_name in ("foo" , "bar" ):
20562057 real_dir = os .path .join (real_dir_root , dir_name )
@@ -2065,7 +2066,7 @@ def create_real_paths(self):
20652066 f .write ("sub" )
20662067 yield real_dir_root
20672068 finally :
2068- shutil .rmtree (real_dir_root , ignore_errors = True )
2069+ shutil .rmtree (temp_directory , ignore_errors = True )
20692070
20702071 def test_existing_fake_directory_is_merged_lazily (self ):
20712072 self .filesystem .create_file (os .path .join ("/" , "root" , "foo" , "test1.txt" ))
@@ -2262,9 +2263,17 @@ def create_symlinks(self, symlinks):
22622263 for link in symlinks :
22632264 os .unlink (link [1 ])
22642265
2266+ @staticmethod
2267+ def _setup_temp_directory ():
2268+ real_directory = tempfile .mkdtemp ()
2269+ os .mkdir (os .path .join (real_directory , "fixtures" ))
2270+ with open (os .path .join (real_directory , "all_tests.py" ), "w" ):
2271+ pass
2272+ return real_directory
2273+
22652274 def test_add_existing_real_directory_symlink (self ):
22662275 fake_open = fake_filesystem .FakeFileOpen (self .filesystem )
2267- real_directory = os . path . join ( self .root_path , "pyfakefs" , "tests" )
2276+ real_directory = self ._setup_temp_directory ( )
22682277 symlinks = [
22692278 (
22702279 ".." ,
@@ -2310,29 +2319,23 @@ def test_add_existing_real_directory_symlink(self):
23102319 self .assertTrue (
23112320 self .filesystem .exists (
23122321 os .path .join (
2313- self .root_path ,
2314- "pyfakefs" ,
2315- "tests" ,
2322+ real_directory ,
23162323 "fixtures/symlink_dir_relative" ,
23172324 )
23182325 )
23192326 )
23202327 self .assertTrue (
23212328 self .filesystem .exists (
23222329 os .path .join (
2323- self .root_path ,
2324- "pyfakefs" ,
2325- "tests" ,
2330+ real_directory ,
23262331 "fixtures/symlink_dir_relative/all_tests.py" ,
23272332 )
23282333 )
23292334 )
23302335 self .assertTrue (
23312336 self .filesystem .exists (
23322337 os .path .join (
2333- self .root_path ,
2334- "pyfakefs" ,
2335- "tests" ,
2338+ real_directory ,
23362339 "fixtures/symlink_file_relative" ,
23372340 )
23382341 )
@@ -2342,29 +2345,23 @@ def test_add_existing_real_directory_symlink(self):
23422345 self .assertTrue (
23432346 self .filesystem .exists (
23442347 os .path .join (
2345- self .root_path ,
2346- "pyfakefs" ,
2347- "tests" ,
2348+ real_directory ,
23482349 "fixtures/symlink_dir_absolute" ,
23492350 )
23502351 )
23512352 )
23522353 self .assertTrue (
23532354 self .filesystem .exists (
23542355 os .path .join (
2355- self .root_path ,
2356- "pyfakefs" ,
2357- "tests" ,
2356+ real_directory ,
23582357 "fixtures/symlink_dir_absolute/all_tests.py" ,
23592358 )
23602359 )
23612360 )
23622361 self .assertTrue (
23632362 self .filesystem .exists (
23642363 os .path .join (
2365- self .root_path ,
2366- "pyfakefs" ,
2367- "tests" ,
2364+ real_directory ,
23682365 "fixtures/symlink_file_absolute" ,
23692366 )
23702367 )
@@ -2374,19 +2371,15 @@ def test_add_existing_real_directory_symlink(self):
23742371 self .assertTrue (
23752372 self .filesystem .exists (
23762373 os .path .join (
2377- self .root_path ,
2378- "pyfakefs" ,
2379- "tests" ,
2374+ real_directory ,
23802375 "fixtures/symlink_file_absolute_outside" ,
23812376 )
23822377 )
23832378 )
23842379 self .assertEqual (
23852380 fake_open (
23862381 os .path .join (
2387- self .root_path ,
2388- "pyfakefs" ,
2389- "tests" ,
2382+ real_directory ,
23902383 "fixtures/symlink_file_absolute_outside" ,
23912384 ),
23922385 encoding = "utf8" ,
@@ -2396,7 +2389,7 @@ def test_add_existing_real_directory_symlink(self):
23962389
23972390 def test_add_existing_real_directory_symlink_target_path (self ):
23982391 self .skip_if_symlink_not_supported (force_real_fs = True )
2399- real_directory = os . path . join ( self .root_path , "pyfakefs" , "tests" )
2392+ real_directory = self ._setup_temp_directory ( )
24002393 symlinks = [
24012394 (
24022395 ".." ,
@@ -2421,7 +2414,7 @@ def test_add_existing_real_directory_symlink_target_path(self):
24212414
24222415 def test_add_existing_real_directory_symlink_lazy_read (self ):
24232416 self .skip_if_symlink_not_supported (force_real_fs = True )
2424- real_directory = os . path . join ( self .root_path , "pyfakefs" , "tests" )
2417+ real_directory = self ._setup_temp_directory ( )
24252418 symlinks = [
24262419 (
24272420 ".." ,
0 commit comments