Skip to content

pathlib.Path() inconsistent behavior #657

Discussion options

You must be logged in to vote

This is a known limitation to pyfakefs (and other patching methods). From the documentation of the modules_to_reload argument:

If initializing a global variable using a file system function, the initialization will be done using the real file system:

from pathlib import Path

path = Path("/example_home")

In this case, path will hold the real file system path inside the test. The same is true, if a file system function is used in a decorator (...).
To get these cases to work as expected under test, the respective modules containing the code shall be added to the modules_to_reload argument (a module list). The passed modules will be reloaded, thus allowing pyfakefs to patch them dynamica…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by sodul
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #655 on January 14, 2022 22:00.