Skip to content
Snippets Groups Projects

force `subprocess.run` to check return code is 0

Merged Hans Fangohr requested to merge force-checking-of-error-code into linux-debian11
+ 14
11
@@ -38,7 +38,9 @@ def create_mock_git_repository(target_directory, create_directory=True):
@@ -38,7 +38,9 @@ def create_mock_git_repository(target_directory, create_directory=True):
# that.
# that.
user_details = "-c user.name='Tes Ta' -c user.email='tester@some-ci.org'"
user_details = "-c user.name='Tes Ta' -c user.email='tester@some-ci.org'"
subprocess.run(
subprocess.run(
f'git {user_details} commit -m "first commit" readme.txt', shell=True, check=True
f'git {user_details} commit -m "first commit" readme.txt',
 
shell=True,
 
check=True,
)
)
@@ -87,17 +89,18 @@ def test_prepare_environment(tmp_path):
@@ -87,17 +89,18 @@ def test_prepare_environment(tmp_path):
assert release_base_dir.exists()
assert release_base_dir.exists()
# check for spack-environments directory
# check for spack-environments directory
assert spack_environments in os.listdir(release_base_dir)
assert spack_environments in os.listdir(release_base_dir)
# check if the git branch is correctly checked out
assert (
# check if the git branch is correctly checked out. We expect output such as
subprocess.run(
# git_branch_stdout = '* dev-23a\n develop\n'
f"cd {str(release_base_dir/spack_environments)} && git branch",
# The entry with the '* ' prefix is the active branch.
shell=True,
git_branch_output_raw = subprocess.run(
capture_output=True,
f"cd {str(release_base_dir/spack_environments)} && git branch",
)
shell=True,
.stdout.decode("utf-8")
capture_output=True,
.split("\n")[0]
== f"* {mpsd_release_to_test}"
)
)
 
git_branch_stdout = git_branch_output_raw.stdout.decode("utf-8")
 
assert f"* {mpsd_release_to_test}" in git_branch_stdout
 
# check that result is a list and contains atleast ['global','foss2021a-mpi']
# check that result is a list and contains atleast ['global','foss2021a-mpi']
assert isinstance(result, list)
assert isinstance(result, list)
assert "global" in result
assert "global" in result
Loading