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

FakeOsModule.walk return a (Path, list, list) generator instead of a (str, list, list) when a pathlib object is used as input #915

Closed
PapaNoyel opened this issue Nov 27, 2023 · 5 comments · Fixed by #916
Labels

Comments

@PapaNoyel
Copy link

PapaNoyel commented Nov 27, 2023

Hi !

I encountered this while creating tests in pytest on my Windows machine.

Describe the bug
method FakeOsModule.walk of <pyfakefs.fake_os.FakeOsModule> is returning a Path object as first element instead of a string as the os.walk method do.

How To Reproduce

from pathlib import Path

# Real os part
import os
os_output = list(os.walk(Path(os.getcwd())))  # Deepest element is a tuple of [str, list, list]
# Example ("C:\\", [], [])

# Fake os part
from pyfakefs import fake_filesystem, fake_os
filesystem = fake_filesystem.FakeFilesystem()
os_module = fake_os.FakeOsModule(filesystem)
fs_output = list(os_module.walk(Path(os_module.getcwd())))  # Deepest element is a tuple of [WindowsPath, list, list]
# Example (WindowsPath(C:\), list, list)
fs_output_str = list(os_module.walk(os_module.getcwd()))  # Deepest element is a tuple of [str, list, list] like os.walk
# Example ("C:\\", [], [])

# Warning as walk will return a tuple if there is no subdirectory or a list of tuple otherwise 
assert type(os_output[0][...][0]) is type(fs_output[0])  # Adapt the element to look at the first element of one of the deepest tuples

Your environment
platform.platform: Windows-10-10.0.22621-SP0
sys.version: Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct 2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)]
pyfakefs: 5.3.1
pytest: 7.4.3

If you need more information, don't hesitate

@mrbean-bremen
Copy link
Member

Good catch, thanks! Should be easy to reproduce and to fix.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Nov 27, 2023
- used to return a Path object for the top dir
  instead of a string
- fixes pytest-dev#915
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Nov 27, 2023
- used to return a Path object for the top dir
  instead of a string
- fixes pytest-dev#915
mrbean-bremen added a commit that referenced this issue Nov 28, 2023
- used to return a Path object for the top dir
  instead of a string
- fixes #915
@mrbean-bremen
Copy link
Member

Should be fixed in main now, please check!

@PapaNoyel
Copy link
Author

Didn't think it would be this fast to be patched ! Thanks a lot !

I've tested the main branch, it is now working as expected, thanks again for maintaining this library ! <3

@mrbean-bremen
Copy link
Member

You are welcome! As I wrote, this one was easy... There is another open issue which I want to get fixed, after that I'll make a new patch release.

@mrbean-bremen
Copy link
Member

FYI: A new patch release is out.

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

Successfully merging a pull request may close this issue.

2 participants