@@ -2050,7 +2050,8 @@ def test_existing_fake_file_raises(self):
2050
2050
2051
2051
@contextlib .contextmanager
2052
2052
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" )
2054
2055
try :
2055
2056
for dir_name in ("foo" , "bar" ):
2056
2057
real_dir = os .path .join (real_dir_root , dir_name )
@@ -2065,7 +2066,7 @@ def create_real_paths(self):
2065
2066
f .write ("sub" )
2066
2067
yield real_dir_root
2067
2068
finally :
2068
- shutil .rmtree (real_dir_root , ignore_errors = True )
2069
+ shutil .rmtree (temp_directory , ignore_errors = True )
2069
2070
2070
2071
def test_existing_fake_directory_is_merged_lazily (self ):
2071
2072
self .filesystem .create_file (os .path .join ("/" , "root" , "foo" , "test1.txt" ))
@@ -2262,9 +2263,17 @@ def create_symlinks(self, symlinks):
2262
2263
for link in symlinks :
2263
2264
os .unlink (link [1 ])
2264
2265
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
+
2265
2274
def test_add_existing_real_directory_symlink (self ):
2266
2275
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 ( )
2268
2277
symlinks = [
2269
2278
(
2270
2279
".." ,
@@ -2310,29 +2319,23 @@ def test_add_existing_real_directory_symlink(self):
2310
2319
self .assertTrue (
2311
2320
self .filesystem .exists (
2312
2321
os .path .join (
2313
- self .root_path ,
2314
- "pyfakefs" ,
2315
- "tests" ,
2322
+ real_directory ,
2316
2323
"fixtures/symlink_dir_relative" ,
2317
2324
)
2318
2325
)
2319
2326
)
2320
2327
self .assertTrue (
2321
2328
self .filesystem .exists (
2322
2329
os .path .join (
2323
- self .root_path ,
2324
- "pyfakefs" ,
2325
- "tests" ,
2330
+ real_directory ,
2326
2331
"fixtures/symlink_dir_relative/all_tests.py" ,
2327
2332
)
2328
2333
)
2329
2334
)
2330
2335
self .assertTrue (
2331
2336
self .filesystem .exists (
2332
2337
os .path .join (
2333
- self .root_path ,
2334
- "pyfakefs" ,
2335
- "tests" ,
2338
+ real_directory ,
2336
2339
"fixtures/symlink_file_relative" ,
2337
2340
)
2338
2341
)
@@ -2342,29 +2345,23 @@ def test_add_existing_real_directory_symlink(self):
2342
2345
self .assertTrue (
2343
2346
self .filesystem .exists (
2344
2347
os .path .join (
2345
- self .root_path ,
2346
- "pyfakefs" ,
2347
- "tests" ,
2348
+ real_directory ,
2348
2349
"fixtures/symlink_dir_absolute" ,
2349
2350
)
2350
2351
)
2351
2352
)
2352
2353
self .assertTrue (
2353
2354
self .filesystem .exists (
2354
2355
os .path .join (
2355
- self .root_path ,
2356
- "pyfakefs" ,
2357
- "tests" ,
2356
+ real_directory ,
2358
2357
"fixtures/symlink_dir_absolute/all_tests.py" ,
2359
2358
)
2360
2359
)
2361
2360
)
2362
2361
self .assertTrue (
2363
2362
self .filesystem .exists (
2364
2363
os .path .join (
2365
- self .root_path ,
2366
- "pyfakefs" ,
2367
- "tests" ,
2364
+ real_directory ,
2368
2365
"fixtures/symlink_file_absolute" ,
2369
2366
)
2370
2367
)
@@ -2374,19 +2371,15 @@ def test_add_existing_real_directory_symlink(self):
2374
2371
self .assertTrue (
2375
2372
self .filesystem .exists (
2376
2373
os .path .join (
2377
- self .root_path ,
2378
- "pyfakefs" ,
2379
- "tests" ,
2374
+ real_directory ,
2380
2375
"fixtures/symlink_file_absolute_outside" ,
2381
2376
)
2382
2377
)
2383
2378
)
2384
2379
self .assertEqual (
2385
2380
fake_open (
2386
2381
os .path .join (
2387
- self .root_path ,
2388
- "pyfakefs" ,
2389
- "tests" ,
2382
+ real_directory ,
2390
2383
"fixtures/symlink_file_absolute_outside" ,
2391
2384
),
2392
2385
encoding = "utf8" ,
@@ -2396,7 +2389,7 @@ def test_add_existing_real_directory_symlink(self):
2396
2389
2397
2390
def test_add_existing_real_directory_symlink_target_path (self ):
2398
2391
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 ( )
2400
2393
symlinks = [
2401
2394
(
2402
2395
".." ,
@@ -2421,7 +2414,7 @@ def test_add_existing_real_directory_symlink_target_path(self):
2421
2414
2422
2415
def test_add_existing_real_directory_symlink_lazy_read (self ):
2423
2416
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 ( )
2425
2418
symlinks = [
2426
2419
(
2427
2420
".." ,
0 commit comments