AttributeError: type object 'Path' has no attribute '_flavour' - error seen when using Click 8 #605
Replies: 6 comments
-
Thanks for the report! I had a first look, and I'm not sure yet what to do in this case. As I will have a closer look, but cannot promise anything yet. |
Beta Was this translation helpful? Give feedback.
-
@mrbean-bremen - Thanks so much for the quick response! I really appreciate the project and your work on it. Workarounds / anything like that are welcome if any come to mind. |
Beta Was this translation helpful? Give feedback.
-
Sorry, didn't get anywhere - I need to have a look at this someday with a fresh eye. |
Beta Was this translation helpful? Give feedback.
-
No need to be sorry! |
Beta Was this translation helpful? Give feedback.
-
Ok, now with a fresh brain I can see that I obviously did a mistake last time I checked this. Sorry it took so long, looks like I needed the weekend to clear my head... The problem is, as stated above, that the decorator is evaluated at load time, before the patcher had a chance to patch it. The only way to work around this is to reload the module during the test, so that the decorator will be re-evaluated. This assumes that you have the sut and the test in different modules. Here is a version that worked for me: pyfakefs_tests/pathlib_click.py import pathlib
import click
@click.command()
@click.argument('foo', type=click.Path(path_type=pathlib.Path))
def hello(foo):
print(foo) pyfakefs_tests/test_pathlib_click.py from pyfakefs.fake_filesystem_unittest import Patcher
from pyfakefs_tests import pathlib_click
with Patcher(modules_to_reload=[pathlib_click]):
pathlib_click.hello(['/']) Note that in this case it is essential not to do from pyfakefs.fake_filesystem_unittest import Patcher
from pyfakefs_tests import pathlib_click
with Patcher(modules_to_reload=[pathlib_click]):
from pathlib_click import hello
hello(['/']) Note that these problems are not specific to |
Beta Was this translation helpful? Give feedback.
-
@mrbean-bremen - No need to apologise, and thank you for your time and thought. I'm happy to work around this and I appreciate your work. I'll leave the choice of whether to close this to you. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
In Click 8, a new feature was introduced, enabling users to use
pathlib.Path
asa type for arguments.
This indirectly uses the
_flavour
attribute ofPath
.This errors when I use PyFakeFS.
I get the following error:
I believe that this may be related to https://bugs.python.org/issue24132.
How To Reproduce
Realistic use case
Narrow use case
Your environment
Beta Was this translation helpful? Give feedback.
All reactions