diff --git a/tests.py b/tests.py
index 42d1e74483f8b2f6ec1f751a011d18dfd3bf430d..26aa05e27c6ee056f7387c8d086852ea7dd33b6c 100644
--- a/tests.py
+++ b/tests.py
@@ -89,17 +89,18 @@ def test_prepare_environment(tmp_path):
     assert release_base_dir.exists()
     # check for spack-environments directory
     assert spack_environments in os.listdir(release_base_dir)
-    # check if the git branch is correctly checked out
-    assert (
-        subprocess.run(
-            f"cd {str(release_base_dir/spack_environments)} && git branch",
-            shell=True,
-            capture_output=True,
-        )
-        .stdout.decode("utf-8")
-        .split("\n")[0]
-        == f"* {mpsd_release_to_test}"
+
+    # check if the git branch is correctly checked out. We expect output such as
+    # git_branch_stdout = '* dev-23a\n  develop\n'
+    # The entry with the '* ' prefix is the active branch.
+    git_branch_output_raw = subprocess.run(
+        f"cd {str(release_base_dir/spack_environments)} && git branch",
+        shell=True,
+        capture_output=True,
     )
+    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']
     assert isinstance(result, list)
     assert "global" in result