Repository: reanahub/reana-client

Issue:
cli: `start` showing success message when workflow fails
In the `start` command, when including the `--follow` flag, the program prints a success message when the workflow stops, even if it was stopped or failed, resulting in a message like `==> SUCCESS: workflow has been failed`.

We should improve this behavior and only display a success message when the workflow finished correctly. For the other cases, an error or info message is probably more better.

Discussion:

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b2de68d..56a7a66 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -195,7 +195,7 @@ jobs:
 
           - name: Install Python dependencies
             run: |
-              pip install -I -r .${{ matrix.testenv }}-requirements.txt
+              pip install -r .${{ matrix.testenv }}-requirements.txt
 
           - name: Run pytest
             run: ./run-tests.sh --check-pytest
diff --git a/reana_client/cli/workflow.py b/reana_client/cli/workflow.py
index d1327b7..b07af96 100644
--- a/reana_client/cli/workflow.py
+++ b/reana_client/cli/workflow.py
@@ -455,6 +455,15 @@ def workflow_start(
         start_workflow,
     )
 
+    def display_status(workflow: str, current_status: str):
+        """Display the current status of the workflow."""
+        status_msg = get_workflow_status_change_msg(workflow, current_status)
+        if current_status in ["deleted", "failed", "stopped"]:
+            display_message(status_msg, msg_type="error")
+            sys.exit(1)
+        else:
+            display_message(status_msg, msg_type="success")
+
     logging.debug("command: {}".format(ctx.command_path.replace(" ", ".")))
     for p in ctx.params:
         logging.debug("{param}: {value}".format(param=p, value=ctx.params[p]))
@@ -487,36 +496,28 @@ def workflow_start(
             logging.info("Connecting to {0}".format(get_api_url()))
             response = start_workflow(workflow, access_token, parsed_parameters)
             current_status = get_workflow_status(workflow, access_token).get("status")
-            display_message(
-                get_workflow_status_change_msg(workflow, current_status),
-                msg_type="success",
-            )
+            display_status(workflow, current_status)
+
             if follow:
+                # keep printing the current status of the workflow
                 while current_status in ["pending", "queued", "running"]:
                     time.sleep(TIMECHECK)
                     current_status = get_workflow_status(workflow, access_token).get(
                         "status"
                     )
-                    display_message(
-                        get_workflow_status_change_msg(workflow, current_status),
-                        msg_type="success",
-                    )
+                    display_status(workflow, current_status)
+
                     if current_status == "finished":
-                        if follow:
-                            display_message(
-                                "Listing workflow output files...",
-                                msg_type="info",
-                            )
-                            ctx.invoke(
-                                get_files,
-                                workflow=workflow,
-                                access_token=access_token,
-                                output_format="url",
-                                human_readable_or_raw="raw",
-                            )
-                        sys.exit(0)
-                    elif current_status in ["deleted", "failed", "stopped"]:
-                        sys.exit(1)
+                        display_message(
+                            "Listing workflow output files...", msg_type="info"
+                        )
+                        ctx.invoke(
+                            get_files,
+                            workflow=workflow,
+                            access_token=access_token,
+                            output_format="url",
+                            human_readable_or_raw="raw",
+                        )
         except Exception as e:
             logging.debug(traceback.format_exc())
             logging.debug(str(e))


Test patch:
diff --git a/tests/test_cli_workflows.py b/tests/test_cli_workflows.py
index 3f0d145..c3ddd24 100644
--- a/tests/test_cli_workflows.py
+++ b/tests/test_cli_workflows.py
@@ -540,10 +540,19 @@ def test_create_workflow_from_json(create_yaml_workflow_schema):
 
 
 @pytest.mark.parametrize(
-    "status",
-    ["created", "running", "finished", "failed", "deleted", "stopped", "queued"],
+    "status, exit_code",
+    [
+        ("created", 0),
+        ("pending", 0),
+        ("queued", 0),
+        ("running", 0),
+        ("finished", 0),
+        ("failed", 1),
+        ("deleted", 1),
+        ("stopped", 1),
+    ],
 )
-def test_workflow_start_successful(status):
+def test_workflow_start_successful(status, exit_code):
     """Test workflow start when creation is successfull."""
     workflow_name = "mytest.1"
     response = {
@@ -569,7 +578,7 @@ def test_workflow_start_successful(status):
             result = runner.invoke(
                 cli, ["start", "-t", reana_token, "-w", response["workflow_name"]]
             )
-            assert result.exit_code == 0
+            assert result.exit_code == exit_code
             assert expected_message in result.output