From 53f9a024423707f746fd02ffa256e240013c57a3 Mon Sep 17 00:00:00 2001 From: Paul Morgan Date: Tue, 18 Feb 2014 03:24:41 +0000 Subject: [PATCH] avoid TB in nose tests if there is no tty GitPython's git.util.get_user_id() calls os.getlogin(), which throws an OSError if there is no tty: Traceback (most recent call last): File "/home/sandbox/test/functional/multiproject_tests.py", line 65, in setUp TitoGitTestFixture.setUp(self) File "/home/sandbox/test/functional/fixture.py", line 129, in setUp index.commit('Setting offline.') File "/usr/lib/python2.7/site-packages/git/index/base.py", line 887, in commit return Commit.create_from_tree(self.repo, tree, message, parent_commits, head) File "/usr/lib/python2.7/site-packages/git/objects/commit.py", line 303, in create_from_tree committer = Actor.committer(cr) File "/usr/lib/python2.7/site-packages/git/util.py", line 354, in committer return cls._main_actor(cls.env_committer_name, cls.env_committer_email, config_reader) File "/usr/lib/python2.7/site-packages/git/util.py", line 327, in _main_actor default_email = get_user_id() File "/usr/lib/python2.7/site-packages/git/util.py", line 120, in get_user_id username = os.getlogin() OSError: [Errno 25] Inappropriate ioctl for device But GitPython also allows to avoid the call by setting environment variable "USER" to anything other than "UNKNOWN". Therefore we preempt GitPython by calling os.getlogin() ourselves. If we have to rescue the exception, export the environment var to avoid traceback. --- test/functional/fixture.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/functional/fixture.py b/test/functional/fixture.py index 232968b..9fabdeb 100644 --- a/test/functional/fixture.py +++ b/test/functional/fixture.py @@ -117,6 +117,13 @@ class TitoGitTestFixture(unittest.TestCase): print("Testing in: %s" % self.repo_dir) print + # GitPython calls os.login(), which throws OSError if there is no tty, + # but GitPython allows to avoid the call if env var USER exists. + try: + os.getlogin() + except OSError: + os.environ['USER'] = 'nobody' + # Initialize the repo: self.repo = git.Repo.init(path=self.repo_dir, mkdir=True, bare=False)