Reputation: 11
Here's a simple piece of code I wanted to test:
import os
def move_all(firstPath, secondPath):
for count, filename in enumerate(os.listdir(firstPath)):
print('moving '+str(count) + ' '+filename)
os.rename((firstPath+'\\'+filename),(secondPath+'\\'+filename))
def test_fakefs(fs):
fakeDirectory = '\\fakeroot\\fakefolder'
fakeFile1 = 'fake_file.txt'
fakeFile2 = 'fake_file_2.txt'
fs.create_dir(fakeDirectory)
fs.create_file(fakeDirectory+"\\"+fakeFile1)
fs.create_file(fakeDirectory+'\\'+fakeFile2)
fs.create_dir(fakeDirectory+'2')
move_all(fakeDirectory,(fakeDirectory+'2'))
assert os.path.exists(fakeDirectory+'2\\fake_file.txt')
When running this using pytest, everything seems to work. However, if I switch 6th line to renames:
os.renames((firstPath+'\\'+filename),(secondPath+'\\'+filename))
I get
FileNotFoundError: [WinError 3] The system cannot find the path specified: '\fakeroot\fakefolder\fake_file.txt' -> '\fakeroot\fakefolder2\fake_file.txt'
Am I doing something wrong or does pyfakefs not support this os method? The very same function works as intended on a real file system.
Upvotes: 1
Views: 82