Skip to content
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

AttributeError: 'FakePipeWrapper' object has no attribute 'delete_on_close' #493

Closed
ghost opened this issue Aug 7, 2019 · 1 comment
Closed

Comments

@ghost
Copy link

ghost commented Aug 7, 2019

Describe the bug
When using plumbum and the fake filesystem I'm unable to run plumbum commands (which uses Popen).

Note you can test what do_something's behavior should be by doing a:

Patricks-MacBook-Pro-2:bugs pburton$ python3
Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from test_plumbum import do_something
>>> do_something()
hello world!

>>> 

How To Reproduce

requirements.txt:

plumbum
pytest
pyfakefs

test_plumbum.py contents:

import pytest

from plumbum.cmd import echo


def do_something():
    e_hello_world = echo["hello world!"]
    print(e_hello_world())


def test_do_something(fs):
    do_something()

Run python3 -m "pytest" test_plumbum.py and you will see the following output:

test_plumbumbug.py F                                                                                                                                                                          [100%]

============================================================================================= FAILURES ==============================================================================================
_________________________________________________________________________________________ test_do_something _________________________________________________________________________________________

fs = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x1114fd128>

    def test_do_something(fs):
>       do_something()

/Users/pburton/bugs/test_plumbumbug.py:12: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/Users/pburton/bugs/test_plumbumbug.py:8: in do_something
    e_hello_world()
/usr/local/lib/python3.7/site-packages/plumbum/commands/base.py:103: in __call__
    return self.run(args, **kwargs)[1]
/usr/local/lib/python3.7/site-packages/plumbum/commands/base.py:239: in run
    with self.bgrun(args, **kwargs) as p:
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py:112: in __enter__
    return next(self.gen)
/usr/local/lib/python3.7/site-packages/plumbum/commands/base.py:193: in bgrun
    p = self.popen(args, **kwargs)
/usr/local/lib/python3.7/site-packages/plumbum/commands/base.py:320: in popen
    return self.cmd.popen(self.args + list(args), **kwargs)
/usr/local/lib/python3.7/site-packages/plumbum/machines/local.py:125: in popen
    **kwargs)
/usr/local/lib/python3.7/site-packages/plumbum/machines/local.py:305: in _popen
    **kwargs)  # bufsize = 4096
/usr/local/lib/python3.7/site-packages/plumbum/machines/local.py:40: in __init__
    self._proc = Popen(*args, **kwargs)
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py:753: in __init__
    self.stdin = io.open(p2cwrite, 'wb', bufsize)
/usr/local/lib/python3.7/site-packages/pyfakefs/fake_filesystem.py:4640: in open
    newline, closefd, opener)
/usr/local/lib/python3.7/site-packages/pyfakefs/fake_filesystem.py:5168: in __call__
    return self.call(*args, **kwargs)
/usr/local/lib/python3.7/site-packages/pyfakefs/fake_filesystem.py:5216: in call
    file_)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pyfakefs.fake_filesystem.FakeFileOpen object at 0x1110650f0>, file_ = 4

    def _handle_file_arg(self, file_):
        file_object = None
        if isinstance(file_, int):
            # opening a file descriptor
            filedes = file_
            wrapper = self.filesystem.get_open_file(filedes)
>           self._delete_on_close = wrapper.delete_on_close
E           AttributeError: 'FakePipeWrapper' object has no attribute 'delete_on_close'

/usr/local/lib/python3.7/site-packages/pyfakefs/fake_filesystem.py:5297: AttributeError

Your enviroment
Please run the following and paste the output.

python3 -c "import platform; print(platform.platform())"
Darwin-18.6.0-x86_64-i386-64bit
python3 -c "import sys; print('Python', sys.version)"
Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)]
python3 -c "from pyfakefs.fake_filesystem import __version__; print('pyfakefs', __version__)"
pyfakefs 3.6
@mrbean-bremen
Copy link
Member

Thanks for the report!
While this concrete exception is probaly easy to fix (and we will certainly do that), I doubt that your example will work anyway as it uses subprocess, which internally uses C calls to access the file system.
You may also check the similar issues #187 and #447.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Sep 13, 2020
mrbean-bremen added a commit that referenced this issue Nov 16, 2021
github-actions bot pushed a commit that referenced this issue Nov 16, 2021
mrbean-bremen added a commit that referenced this issue Nov 16, 2021
github-actions bot pushed a commit that referenced this issue Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant