Skip to content

Commit

Permalink
Refactor according to Jon's suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-harvey-z3q committed Oct 3, 2021
1 parent 4b65dba commit 93a15e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions sceptre/cli/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import os
import sys
import traceback

from itertools import cycle
from functools import partial, wraps
Expand Down Expand Up @@ -32,14 +34,15 @@ def catch_exceptions(func):
def decorated(*args, **kwargs):
"""
Invokes ``func``, catches expected errors, prints the error message and
re-raises.
exits sceptre with a non-zero exit code.
"""
try:
return func(*args, **kwargs)
except (SceptreException, BotoCoreError, ClientError, Boto3Error,
TemplateError) as error:
write(error)
raise
TemplateError):
if "DEBUG_ERRORS" in os.environ:
traceback.print_exc()
sys.exit(1)

return decorated

Expand Down
7 changes: 4 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ def teardown_method(self, test_method):
self.patcher_ConfigReader.stop()
self.patcher_StackActions.stop()

def test_catch_excecptions(self):
@patch("sys.exit")
def test_catch_excecptions(self, mock_exit):
@catch_exceptions
def raises_exception():
raise SceptreException()

with pytest.raises(SceptreException):
raises_exception()
raises_exception()
mock_exit.assert_called_once_with(1)

@pytest.mark.parametrize("command,files,output", [
# one --var option
Expand Down

0 comments on commit 93a15e8

Please sign in to comment.