Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lambda_local/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def execute(func, event, context):
err = sys.exc_info()
result = json.dumps({
"errorMessage": str(err[1]),
"stackTrace": traceback.extract_tb(err[2]),
"stackTrace": traceback.format_tb(err[2]),
"errorType": err[0].__name__
}, indent=4, separators=(',', ': '))
err_type = ERR_TYPE_EXCEPTION
Expand Down
37 changes: 36 additions & 1 deletion tests/test_direct_invocations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
python-lambda-local: Test Direct Inovactions
python-lambda-local: Test Direct Invocations
(command-line and direct).

Meant for use with py.test.
Expand All @@ -13,6 +13,7 @@
import os
from lambda_local.main import run as lambda_run
from lambda_local.main import call as lambda_call
from lambda_local.main import ERR_TYPE_EXCEPTION
from lambda_local.context import Context


Expand All @@ -21,6 +22,10 @@ def my_lambda_function(event, context):
return 42


def my_failing_lambda_function(event, context):
raise Exception('Oh no')


def test_function_call_for_pytest():
(result, error_type) = lambda_call(
my_lambda_function, {}, Context(1))
Expand All @@ -30,6 +35,13 @@ def test_function_call_for_pytest():
assert result == 42


def test_handle_exceptions_gracefully():
(result, error_type) = lambda_call(
my_failing_lambda_function, {}, Context(1))

assert error_type is ERR_TYPE_EXCEPTION


def test_check_command_line():
request = json.dumps({})
request_file = 'check_command_line_event.json'
Expand All @@ -51,3 +63,26 @@ def test_check_command_line():

os.remove(request_file)
assert p.exitcode == 0


def test_check_command_line_error():
request = json.dumps({})
request_file = 'check_command_line_event.json'
with open(request_file, "w") as f:
f.write(request)

args = argparse.Namespace(event=request_file,
file='tests/test_direct_invocations.py',
function='my_failing_lambda_function',
timeout=1,
environment_variables='',
library=None,
version_name='',
arn_string=''
)
p = Process(target=lambda_run, args=(args,))
p.start()
p.join()

os.remove(request_file)
assert p.exitcode == 1