Skip to content

Commit

Permalink
Simplify shell test helper with with_exceptions=False
Browse files Browse the repository at this point in the history
Instead of swallowing GitCommandError exceptions in the helper used
by test_it_uses_shell_or_not_as_specified and
test_it_logs_if_it_uses_a_shell, this modifies the helper so it
prevents Git.execute from raising the exception in the first place.
  • Loading branch information
EliahKagan committed Oct 3, 2023
1 parent 2d1efdc commit a8a43fe
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# This module is part of GitPython and is released under
# the BSD License: https://opensource.org/license/bsd-3-clause/
import contextlib
import inspect
import logging
import os
Expand Down Expand Up @@ -97,10 +96,8 @@ def _do_shell_combo(self, value_in_call, value_from_class):
# git.cmd gets Popen via a "from" import, so patch it there.
with mock.patch.object(cmd, "Popen", wraps=cmd.Popen) as mock_popen:
# Use a command with no arguments (besides the program name), so it runs
# with or without a shell, on all OSes, with the same effect. Since git
# errors out when run with no arguments, we swallow that error.
with contextlib.suppress(GitCommandError):
self.git.execute(["git"], shell=value_in_call)
# with or without a shell, on all OSes, with the same effect.
self.git.execute(["git"], with_exceptions=False, shell=value_in_call)

return mock_popen

Expand Down

0 comments on commit a8a43fe

Please sign in to comment.