Patching of os not working properly when using it with behave #854
-
Describe the bug I am raising this issue here because I already tried the same thing using mockfs. Here patching of How To Reproduce There is also a foo.py, which does pretty much the same thing. Your environment
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
Some more info: Just realized that I could check the debugger: |
Beta Was this translation helpful? Give feedback.
-
Looks like I found a "solution" in the meantime. Maybe it is even the way to do this anyways:
Not sure whether this is really as it is supposed to be? |
Beta Was this translation helpful? Give feedback.
-
Interesting - at a first glance, this looks strange, and I have no idea what the problem is. I will have a closer look to understand the problem and will let you know if I find some way to fix this. |
Beta Was this translation helpful? Give feedback.
-
Ok, as far as I understand, the problem is that the There is one workaround I can think of: do not load the file system modules globally in the tests (e.g. in the from behave import given, when, then
@given("pyfakefs set up")
def step_impl(context):
pass
@when('os.mkdir("/foo") is called')
def step_impl(context):
import os
os.mkdir("/foo")
@then('os.path.exists("/foo") will return True')
def step_impl(context):
import os
assert os.path.exists("/foo") (the same goes for This is not very nice, and I'm not sure if it is a practical way for your use case, but right now I can't think of anything else. |
Beta Was this translation helpful? Give feedback.
-
I had a closer look, and indeed Apart from the workaround above I don't see a way to make this work. I'll probably add this to the limitations sections of the documentation. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the analysis. Probably I should raise a bug/feature request against behave? Anyways, for me it will be sufficient to use the os functions in the productive code and only use the wrappers in the test code. That worked fine. |
Beta Was this translation helpful? Give feedback.
-
I think not - that would mean to change the implementation of If you can work with the limitation, I'm inclined to close this issue, as both the limitation and the workaround are now documented in |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late answer. I believe that documenting this issue will be sufficient. |
Beta Was this translation helpful? Give feedback.
I think not - that would mean to change the implementation of
behave
sufficiently, and compatibility withpyfakefs
is not enough of a rationale to do this. This is a limitation ofpyfakefs
, not ofbehave
.If you can work with the limitation, I'm inclined to close this issue, as both the limitation and the workaround are now documented in
pyfakefs
.