Skip to content

os.renames is not patched #714

@mrbean-bremen

Description

@mrbean-bremen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions