diff --git a/getgauge/exceptions.py b/getgauge/exceptions.py index 04fbd90..65b94fa 100644 --- a/getgauge/exceptions.py +++ b/getgauge/exceptions.py @@ -2,3 +2,9 @@ class MultipleImplementationFoundException(Exception): def __init__(self, message): super().__init__(message) self.message = message + + +class SkipScenarioException(Exception): + def __init__(self, message): + super().__init__(message) + self.message = message diff --git a/getgauge/executor.py b/getgauge/executor.py index aeda180..c37b678 100644 --- a/getgauge/executor.py +++ b/getgauge/executor.py @@ -4,9 +4,10 @@ import time import traceback -from getgauge.messages.messages_pb2 import ExecutionStatusResponse, Message +from getgauge.exceptions import SkipScenarioException +from getgauge.messages.messages_pb2 import ExecutionStatusResponse from getgauge.messages.spec_pb2 import ProtoExecutionResult -from getgauge.registry import MessagesStore, ScreenshotsStore, registry +from getgauge.registry import MessagesStore, ScreenshotsStore def create_execution_status_response(): @@ -23,7 +24,8 @@ def run_hook(request, hooks, execution_info): return response -def _false(func, exception): return False +def _false(func, exception): + return False def execute_method(params, step, response, is_continue_on_failure=_false): @@ -31,6 +33,9 @@ def execute_method(params, step, response, is_continue_on_failure=_false): try: params = _get_args(params, step) step.impl(*params) + except SkipScenarioException as e: + response.executionResult.skipScenario = True + MessagesStore.write_message(str(e)) except Exception as e: _add_exception(e, response, is_continue_on_failure(step.impl, e)) response.executionResult.executionTime = _current_time() - start @@ -38,7 +43,8 @@ def execute_method(params, step, response, is_continue_on_failure=_false): response.executionResult.screenshotFiles.extend(ScreenshotsStore.pending_screenshots()) -def _current_time(): return int(round(time.time() * 1000)) +def _current_time(): + return int(round(time.time() * 1000)) def _get_args(params, hook_or_step): @@ -57,7 +63,7 @@ def _add_exception(e, response, continue_on_failure): screenshot = ScreenshotsStore.capture_to_file() response.executionResult.failureScreenshotFile = screenshot response.executionResult.failed = True - message = e.__str__() + message = str(e) if not message: message = "Exception occurred" response.executionResult.errorMessage = message diff --git a/python.json b/python.json index b47fbd4..e64bace 100644 --- a/python.json +++ b/python.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "0.4.6", + "version": "0.4.7", "description": "Python support for gauge", "run": { "windows": [ diff --git a/tests/test_processor.py b/tests/test_processor.py index c1cfe87..45afc0d 100644 --- a/tests/test_processor.py +++ b/tests/test_processor.py @@ -5,6 +5,7 @@ from getgauge import processor from getgauge import static_loader as loader +from getgauge.exceptions import SkipScenarioException from getgauge.messages.messages_pb2 import * from getgauge.messages.spec_pb2 import Parameter, ProtoExecutionResult, Span from getgauge.parser import Parser @@ -183,6 +184,8 @@ def test_Processor_execute_step_request(self): '', response.executionResult.errorMessage) self.assertEqual( '', response.executionResult.stackTrace) + self.assertFalse(response.executionResult.skipScenario) + self.assertEqual([], response.executionResult.message) def test_Processor_execute_step_request_with_param(self): registry.add_step('Step with ', impl, '') @@ -204,6 +207,8 @@ def test_Processor_execute_step_request_with_param(self): '', response.executionResult.errorMessage) self.assertEqual( '', response.executionResult.stackTrace) + self.assertFalse(response.executionResult.skipScenario) + self.assertEqual([], response.executionResult.message) def test_Processor_failed_execute_step_request(self): request = ExecuteStepRequest() @@ -219,6 +224,8 @@ def test_Processor_failed_execute_step_request(self): self.assertNotEqual( '', response.executionResult.stackTrace) self.assertFalse(response.executionResult.recoverableError) + self.assertFalse(response.executionResult.skipScenario) + self.assertEqual([], response.executionResult.message) def test_Processor_failed_execute_step_request_with_continue_on_failure(self): registry.add_step('Step 4', failing_impl, '') @@ -236,6 +243,25 @@ def test_Processor_failed_execute_step_request_with_continue_on_failure(self): self.assertNotEqual('', response.executionResult.errorMessage) self.assertNotEqual('', response.executionResult.stackTrace) self.assertTrue(response.executionResult.recoverableError) + self.assertFalse(response.executionResult.skipScenario) + self.assertEqual([], response.executionResult.message) + + def test_Processor_failed_execute_step_request_with_programmatic_skip(self): + registry.add_step('Skipped Step', skipped_impl, '') + + request = ExecuteStepRequest() + request.parsedStepText = 'Skipped Step' + + response = processor.process_execute_step_request(request) + + self.assertIsInstance(response, ExecutionStatusResponse) + self.assertFalse(response.executionResult.failed) + self.assertEqual( + '', response.executionResult.errorMessage) + self.assertEqual( + '', response.executionResult.stackTrace) + self.assertTrue(response.executionResult.skipScenario) + self.assertEqual(['Step programmatically skipped'], response.executionResult.message) def test_Processor_starting_execution_request(self): registry.add_before_suite(impl1) @@ -748,6 +774,9 @@ def impl2(context): def failing_impl(): print([][1]) +def skipped_impl(): + raise SkipScenarioException("Step programmatically skipped") + if __name__ == '__main__': main()