Skip to content

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

Closed

Description

@hofbi

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

Activity

  1. mrbean-bremen commented on Nov 16, 2021

    @mrbean-bremen
    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.

  2. hofbi commented on Nov 16, 2021

    @hofbi
    ContributorAuthor

    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?

  3. mrbean-bremen commented on Nov 16, 2021

    @mrbean-bremen
    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.

  4. locked and limited conversation to collaborators on Jul 2, 2023
  5. converted this issue into a discussion #857 on Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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