Skip to content

Commit 8ed4e4a

Browse files
Skip test scenarios at runtime (#397)
* Skip test scenarions at runtime Signed-off-by: sschulz92 <[email protected]> * Add unit test for skipped step processing Signed-off-by: Chad Wilson <[email protected]> --------- Signed-off-by: sschulz92 <[email protected]> Signed-off-by: Chad Wilson <[email protected]> Co-authored-by: Chad Wilson <[email protected]>
1 parent e2a3ae7 commit 8ed4e4a

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

getgauge/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ class MultipleImplementationFoundException(Exception):
22
def __init__(self, message):
33
super().__init__(message)
44
self.message = message
5+
6+
7+
class SkipScenarioException(Exception):
8+
def __init__(self, message):
9+
super().__init__(message)
10+
self.message = message

getgauge/executor.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import time
55
import traceback
66

7-
from getgauge.messages.messages_pb2 import ExecutionStatusResponse, Message
7+
from getgauge.exceptions import SkipScenarioException
8+
from getgauge.messages.messages_pb2 import ExecutionStatusResponse
89
from getgauge.messages.spec_pb2 import ProtoExecutionResult
9-
from getgauge.registry import MessagesStore, ScreenshotsStore, registry
10+
from getgauge.registry import MessagesStore, ScreenshotsStore
1011

1112

1213
def create_execution_status_response():
@@ -23,22 +24,27 @@ def run_hook(request, hooks, execution_info):
2324
return response
2425

2526

26-
def _false(func, exception): return False
27+
def _false(func, exception):
28+
return False
2729

2830

2931
def execute_method(params, step, response, is_continue_on_failure=_false):
3032
start = _current_time()
3133
try:
3234
params = _get_args(params, step)
3335
step.impl(*params)
36+
except SkipScenarioException as e:
37+
response.executionResult.skipScenario = True
38+
MessagesStore.write_message(str(e))
3439
except Exception as e:
3540
_add_exception(e, response, is_continue_on_failure(step.impl, e))
3641
response.executionResult.executionTime = _current_time() - start
3742
response.executionResult.message.extend(MessagesStore.pending_messages())
3843
response.executionResult.screenshotFiles.extend(ScreenshotsStore.pending_screenshots())
3944

4045

41-
def _current_time(): return int(round(time.time() * 1000))
46+
def _current_time():
47+
return int(round(time.time() * 1000))
4248

4349

4450
def _get_args(params, hook_or_step):
@@ -57,7 +63,7 @@ def _add_exception(e, response, continue_on_failure):
5763
screenshot = ScreenshotsStore.capture_to_file()
5864
response.executionResult.failureScreenshotFile = screenshot
5965
response.executionResult.failed = True
60-
message = e.__str__()
66+
message = str(e)
6167
if not message:
6268
message = "Exception occurred"
6369
response.executionResult.errorMessage = message

python.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "python",
3-
"version": "0.4.6",
3+
"version": "0.4.7",
44
"description": "Python support for gauge",
55
"run": {
66
"windows": [

tests/test_processor.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from getgauge import processor
77
from getgauge import static_loader as loader
8+
from getgauge.exceptions import SkipScenarioException
89
from getgauge.messages.messages_pb2 import *
910
from getgauge.messages.spec_pb2 import Parameter, ProtoExecutionResult, Span
1011
from getgauge.parser import Parser
@@ -183,6 +184,8 @@ def test_Processor_execute_step_request(self):
183184
'', response.executionResult.errorMessage)
184185
self.assertEqual(
185186
'', response.executionResult.stackTrace)
187+
self.assertFalse(response.executionResult.skipScenario)
188+
self.assertEqual([], response.executionResult.message)
186189

187190
def test_Processor_execute_step_request_with_param(self):
188191
registry.add_step('Step <a> with <b>', impl, '')
@@ -204,6 +207,8 @@ def test_Processor_execute_step_request_with_param(self):
204207
'', response.executionResult.errorMessage)
205208
self.assertEqual(
206209
'', response.executionResult.stackTrace)
210+
self.assertFalse(response.executionResult.skipScenario)
211+
self.assertEqual([], response.executionResult.message)
207212

208213
def test_Processor_failed_execute_step_request(self):
209214
request = ExecuteStepRequest()
@@ -219,6 +224,8 @@ def test_Processor_failed_execute_step_request(self):
219224
self.assertNotEqual(
220225
'', response.executionResult.stackTrace)
221226
self.assertFalse(response.executionResult.recoverableError)
227+
self.assertFalse(response.executionResult.skipScenario)
228+
self.assertEqual([], response.executionResult.message)
222229

223230
def test_Processor_failed_execute_step_request_with_continue_on_failure(self):
224231
registry.add_step('Step 4', failing_impl, '')
@@ -236,6 +243,25 @@ def test_Processor_failed_execute_step_request_with_continue_on_failure(self):
236243
self.assertNotEqual('', response.executionResult.errorMessage)
237244
self.assertNotEqual('', response.executionResult.stackTrace)
238245
self.assertTrue(response.executionResult.recoverableError)
246+
self.assertFalse(response.executionResult.skipScenario)
247+
self.assertEqual([], response.executionResult.message)
248+
249+
def test_Processor_failed_execute_step_request_with_programmatic_skip(self):
250+
registry.add_step('Skipped Step', skipped_impl, '')
251+
252+
request = ExecuteStepRequest()
253+
request.parsedStepText = 'Skipped Step'
254+
255+
response = processor.process_execute_step_request(request)
256+
257+
self.assertIsInstance(response, ExecutionStatusResponse)
258+
self.assertFalse(response.executionResult.failed)
259+
self.assertEqual(
260+
'', response.executionResult.errorMessage)
261+
self.assertEqual(
262+
'', response.executionResult.stackTrace)
263+
self.assertTrue(response.executionResult.skipScenario)
264+
self.assertEqual(['Step programmatically skipped'], response.executionResult.message)
239265

240266
def test_Processor_starting_execution_request(self):
241267
registry.add_before_suite(impl1)
@@ -748,6 +774,9 @@ def impl2(context):
748774
def failing_impl():
749775
print([][1])
750776

777+
def skipped_impl():
778+
raise SkipScenarioException("Step programmatically skipped")
779+
751780

752781
if __name__ == '__main__':
753782
main()

0 commit comments

Comments
 (0)