Skip to content

Patching of os not working properly when using it with behave #703

@schwaerz

Description

@schwaerz

Describe the bug
Last two days I tried to get pyfakefs working with behave. Unfortunately I could not get it done. When I run the same code using plain python, the fakefs is working as expected. But when I run behave to execute the tests, calls to os.mkdir(), os.makedirs() or os.path.exists() will be executed on the actual file system. File I/O still will be done on the patched filesystem, though.

I am raising this issue here because I already tried the same thing using mockfs. Here patching of os.makedirs() and os.path.exists() works as expected, even when running using behave. Unfortunately mockfs does not provide all the features I need, therefore I'd love to use pyfakefs.

How To Reproduce
Use the small project attached, install requirements and run behave. It should fail to creating the directory as tried in environment.py.
behave-pyfakefs.tar.gz

There is also a foo.py, which does pretty much the same thing. python foo.py will work as expected.

Your environment

Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python 3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0]
pyfakefs 4.6.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions