Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.renames is not patched #714

Closed
mrbean-bremen opened this issue Sep 16, 2022 · 0 comments
Closed

os.renames is not patched #714

mrbean-bremen opened this issue Sep 16, 2022 · 0 comments
Labels

Comments

@mrbean-bremen
Copy link
Member

This is copied from stackoverflow:

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.


This can be reproduced with different Python versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant