From 4e5f463c37e2d852a39e014ec0987eccb4072750 Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Fri, 24 Apr 2020 22:28:40 +0200 Subject: [PATCH] chore: Do not show Click's "Aborted!" message when an error occurs during schema loading in CLI --- docs/changelog.rst | 1 + src/schemathesis/cli/__init__.py | 6 +++++- test/cli/test_commands.py | 2 -- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index ec84c2e357..eca477aeeb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -25,6 +25,7 @@ Changed - Added indentation & section name to the ``SUMMARY`` CLI block. - Use C-extension for YAML loading when it is possible. It can cause more than 10x speedup on schema parsing. +- Do not show Click's "Aborted!" message when an error occurs during schema loading in CLI. `1.2.0`_ - 2020-04-15 --------------------- diff --git a/src/schemathesis/cli/__init__.py b/src/schemathesis/cli/__init__.py index ba75178704..16df6c49ed 100644 --- a/src/schemathesis/cli/__init__.py +++ b/src/schemathesis/cli/__init__.py @@ -1,3 +1,4 @@ +import sys import traceback from enum import Enum from typing import Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union @@ -272,7 +273,10 @@ def execute( handler.handle_event(context, event) except click.exceptions.Exit: raise - except Exception: + except Exception as exc: for handler in handlers: handler.shutdown() + if isinstance(exc, click.Abort): + # To avoid showing "Aborted!" message, which is the default behavior in Click + sys.exit(1) raise diff --git a/test/cli/test_commands.py b/test/cli/test_commands.py index 43237a7000..dd9c5800ce 100644 --- a/test/cli/test_commands.py +++ b/test/cli/test_commands.py @@ -695,7 +695,6 @@ def test_schema_not_available(cli, workers): "Error: requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=1): " "Max retries exceeded with url: /swagger.yaml" ) - assert lines[-2] == "Aborted!" def test_schema_not_available_wsgi(cli, loadable_flask_app): @@ -706,7 +705,6 @@ def test_schema_not_available_wsgi(cli, loadable_flask_app): # And error message is displayed lines = result.stdout.split("\n") assert lines[0] == "Schema was not found at unknown.yaml" - assert lines[1] == "Aborted!" @pytest.mark.endpoints("custom_format")