Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

GitPython causes AttributeError: 'FakePipeWrapper' object has no attribute 'closed' #649

Closed
hofbi opened this issue Nov 16, 2021 · 3 comments

Comments

@hofbi
Copy link
Contributor

hofbi commented Nov 16, 2021

Describe the bug

If I am writing functions that interact with a git repository, I usually use GitPython.
To test these function, pyfakefs would be great.
So far, it seems that it is not supported.
Additionally, it is not listed in https://jmcgeheeiv.github.io/pyfakefs/master/usage.html#modules-not-working-with-pyfakefs

MWE and stacktrace below

How To Reproduce

Please provide a unit test or a minimal code snippet that reproduces the
problem.

from pyfakefs.fake_filesystem_unittest import TestCase
import git


class GitTest(TestCase):
    def setUp(self) -> None:
        self.setUpPyfakefs()

    def test_git(self):
        self.fs.create_dir("test")
        git.Repo.init("test")
Error
Traceback (most recent call last):
  File "mwe.py", line 16, in test_git
    git.Repo.init("test")
  File "venv/lib/python3.8/site-packages/git/repo/base.py", line 1046, in init
    git.init(**kwargs)
  File "venv/lib/python3.8/site-packages/git/cmd.py", line 638, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "venv/lib/python3.8/site-packages/git/cmd.py", line 1183, in _call_process
    return self.execute(call, **exec_kwargs)
  File "venv/lib/python3.8/site-packages/git/cmd.py", line 937, in execute
    stdout_value, stderr_value = proc.communicate()
  File "/usr/lib/python3.8/subprocess.py", line 1028, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/lib/python3.8/subprocess.py", line 1853, in _communicate
    if self.stdout and not self.stdout.closed:
AttributeError: 'FakePipeWrapper' object has no attribute 'closed'

Your environment

Linux-5.4.0-90-generic-x86_64-with-glibc2.29
Python 3.8.10
[GCC 9.3.0]
pyfakefs 4.5.3
git 3.1.24
@mrbean-bremen
Copy link
Member

Thanks for the report!
I will have a look later, but unfortunately, I'm not sure if this can be fixed. subprocess is in the list of modules that don't work with pyfakefs, so even if I could fix this concrete problem, it still might not work.

@hofbi
Copy link
Contributor Author

hofbi commented Nov 16, 2021

Right. Then I guess fixing this won't give us much as I expect subprocess to be used in the entire project.

To close this issue, we could add GitPython to the list of modules that don't work with pyfakefs to make this more clear.

Do you have any other idea how to test interaction with git repositories without actually accessing the file system?

@mrbean-bremen
Copy link
Member

I had another look, and I currently see no possibility to use this with pyfakefs - added a note in the documentation as proposed.
For testing this, you probably have to use the real file system, for example by creating a repository in a temp dir, or by using a RAM disk.

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
@hofbi hofbi closed this as completed Nov 16, 2021
@pytest-dev pytest-dev locked and limited conversation to collaborators Jul 2, 2023
@mrbean-bremen mrbean-bremen converted this issue into discussion #857 Jul 2, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants