Skip to content

Commit 4041e0e

Browse files
committed
check_call_suppress_output: Print errors.
1 parent bcfc0ea commit 4041e0e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

test/test_utils/git_helpers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66

77
def make_git_repo():
88
"""Turn the current directory into an empty git repository"""
9-
check_call_suppress_output(['git', 'init'])
9+
check_call_suppress_output(" ".join(['git', 'init']))
1010

1111
def add_git_commit():
1212
"""Add a git commit in the current directory"""
1313
with open('README', 'a') as myfile:
1414
myfile.write('more info')
15-
check_call_suppress_output(['git', 'add', 'README'])
16-
check_call_suppress_output(['git', 'commit', '-m', 'my commit message'])
15+
check_call_suppress_output(" ".join(['git', 'add', 'README']))
16+
check_call_suppress_output("git commit -m 'my commit message'")
1717

1818
def checkout_git_branch(branchname):
1919
"""Checkout a new branch in the current directory"""
20-
check_call_suppress_output(['git', 'checkout', '-b', branchname])
20+
check_call_suppress_output(" ".join(['git', 'checkout', '-b', branchname]))
2121

2222
def make_git_tag(tagname):
2323
"""Make a lightweight tag at the current commit"""
24-
check_call_suppress_output(['git', 'tag', '-m', 'making a tag', tagname])
24+
check_call_suppress_output("git tag -m 'making a tag' " + tagname)
2525

2626
def checkout_git_ref(refname):
2727
"""Checkout the given refname in the current directory"""
28-
check_call_suppress_output(['git', 'checkout', refname])
28+
check_call_suppress_output(" ".join(['git', 'checkout', refname]))

test/test_utils/test_helpers.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
"""General-purpose functions to help with testing"""
22

3-
import os
43
import subprocess
54

65
def check_call_suppress_output(args):
7-
"""Make a check_call call with the given args, suppressing all output"""
8-
with open(os.devnull, 'w') as devnull:
9-
subprocess.check_call(args, stdout=devnull)
6+
"""Make a subprocess call with the given args, suppressing all output unless there's an error"""
7+
try:
8+
subprocess.run(
9+
args,
10+
stdout=subprocess.PIPE,
11+
stderr=subprocess.PIPE,
12+
text=True,
13+
check=True,
14+
shell=True,
15+
)
16+
except subprocess.CalledProcessError as e:
17+
print(f"Command failed with exit code {e.returncode}: {e.cmd}")
18+
print("stdout:")
19+
print(e.stdout)
20+
print("stderr:")
21+
print(e.stderr)
22+
raise

0 commit comments

Comments
 (0)