-
Notifications
You must be signed in to change notification settings - Fork 92
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
pathlib.Path.open is not patched when used with create_file and pytest #420
Comments
Thanks for the report! This is indeed a technical limitation - |
- moved pytest tests into separate subdirectory - the new test is an example for how to work around #420
@ian-h-chamberlain - I added an example that shows how to work around your specific problem using a customized fixture. |
@mrbean-bremen thanks for the quick response! In my case I was able to work around it by instantiating another fs.create_file(EXAMPLE_FILE, contents='stuff here')
with pathlib.Path(EXAMPLE_FILE).open() as file:
assert file.read() == 'stuff here' # this succeeds now In the future I may decide to use a fixture as in your example. This issue can probably be closed now. |
Glad that you found a way to get it working! |
After declaring a
pathlib.Path
at module scope, then the pytestfs
fixture tocreate_file
for that path, subsequent calls topathlib.Path.open
fail with "No such file or directory". A quick look atpathlib.Path.open
shows that it usesio.open
internally.I'm not sure if there's a straightforward way to patch methods of an object declared at module scope, so maybe this is more of a technical limitation than a bug, but I figured it was worth reporting anyway.
master
Minimal example
Output:
The text was updated successfully, but these errors were encountered: