From 6ff8f3aa4a56d3bc1ff29660e9f9069d525d320a Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 21 May 2019 15:05:21 -0400 Subject: [PATCH 1/5] Workaround for features with no elements block Features that don't run any scenarios still show up in the JSON, so we have to avoid making assumptions about the presence of `elements` --- behave2cucumber/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/behave2cucumber/__init__.py b/behave2cucumber/__init__.py index 888bcbf..fe964a9 100644 --- a/behave2cucumber/__init__.py +++ b/behave2cucumber/__init__.py @@ -64,8 +64,9 @@ def format_level(tree, index=0, id_counter=0): # Option to remove background element because behave pushes it steps to all scenarios already if remove_background: for feature in json_file: - if feature['elements'][0]['type'] == 'background': - feature['elements'].pop(0) + if feature.get('elements'): + if feature['elements'][0].get('type') == 'background': + feature['elements'].pop(0) if deduplicate: def check_dupe(current_feature, current_scenario, previous_scenario): @@ -89,7 +90,7 @@ def check_dupe(current_feature, current_scenario, previous_scenario): scenarios = [] # For each scenario in the feature - for scenario in feature['elements']: + for scenario in feature.get('elements', []): # Append the scenario to the working list scenarios.append(scenario) From 70bc6e769ebf54d4fcbc80678c60b078b6ed141e Mon Sep 17 00:00:00 2001 From: Andrew Conti Date: Tue, 6 Jun 2017 23:43:24 -0400 Subject: [PATCH 2/5] Add new option to remove tests with no steps using -e --- behave2cucumber/__init__.py | 16 +++++++++++++++- behave2cucumber/__main__.py | 14 ++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/behave2cucumber/__init__.py b/behave2cucumber/__init__.py index 888bcbf..c379b81 100644 --- a/behave2cucumber/__init__.py +++ b/behave2cucumber/__init__.py @@ -9,7 +9,7 @@ ''' -def convert(json_file, remove_background=False, duration_format=False, deduplicate=False): +def convert(json_file, remove_background=False, duration_format=False, deduplicate=False, remove_empty=False): # json_nodes are the scopes available in behave/cucumber json: Feature -> elements(Scnerios) -> Steps json_nodes = ['feature', 'elements', 'steps'] # These fields doesn't exist in cucumber report, there-fore when converting from behave, we need to delete these @@ -67,6 +67,20 @@ def format_level(tree, index=0, id_counter=0): if feature['elements'][0]['type'] == 'background': feature['elements'].pop(0) + if remove_empty: + for feature in json_file: + # Create a working list + scenarios = [] + + # For each scenario in the feature + for scenario in feature['elements']: + # Add the scenario only if there are steps + if len(scenario['steps']) > 0: + scenarios.append(scenario) + + # Replace the existing list with the working list + feature['elements'] = scenarios + if deduplicate: def check_dupe(current_feature, current_scenario, previous_scenario): if "autoretry" not in current_feature['tags'] and "autoretry" not in current_scenario['tags']: diff --git a/behave2cucumber/__main__.py b/behave2cucumber/__main__.py index 4a185d7..e40404c 100644 --- a/behave2cucumber/__main__.py +++ b/behave2cucumber/__main__.py @@ -24,10 +24,10 @@ options = { - "short": "hd:i:o:rfD", + "short": "hd:i:o:rfDe", "long": [ "help", "debug=", "infile=", "outfile=", "remove-background", - "format-duration","deduplicate" + "format-duration", "deduplicate", "remove-empty" ], "descriptions": [ "Print help message", @@ -36,7 +36,8 @@ "Specify the output JSON, otherwise use stdout", "Remove background steps from output", "Format the duration", - "Remove duplicate scenarios caused by @autoretry" + "Remove duplicate scenarios caused by @autoretry", + "Remove scenarios which contain no steps" ] } @@ -87,6 +88,7 @@ def main(argv): remove_background = False duration_format = False deduplicate = False + remove_empty = False for opt, arg in opts: if opt in ("-i", "--infile"): @@ -104,6 +106,9 @@ def main(argv): if opt in ("-D", "--deduplicate"): log.info("Deduplicate: Enabled") deduplicate = True + if opt in ("-e", "--remove-empty"): + log.info("Remove Empty: Enabled") + remove_empty = True if infile is None: log.critical("No input JSON provided.") @@ -114,7 +119,8 @@ def main(argv): cucumber_output = convert(json.load(f), remove_background=remove_background, duration_format=duration_format, - deduplicate=deduplicate) + deduplicate=deduplicate, + remove_empty=remove_empty) if outfile is not None: with open(outfile, 'w') as f: From 66c9d9431b0b3bb6d1ac5ca0c018b59e0bf1374b Mon Sep 17 00:00:00 2001 From: lawnmowerlatte Date: Wed, 3 Jun 2020 15:10:50 -0400 Subject: [PATCH 3/5] Bump version and add metadata --- setup.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 2163ac5..1e22237 100644 --- a/setup.py +++ b/setup.py @@ -6,14 +6,15 @@ setup( name='behave2cucumber', - version='1.0.3', + version='1.0.4.1', - description='Behave to Cucumber json converter', + description='Behave to Cucumber json converter (lawnmowerlatte fork)', long_description='This project helps solving the incompatibilty of Behave\'s genereated json reports ' 'to tools using Cucumber json reports. ' - 'Its done by reformatting the Behave json to Cucumber json.', + 'Its done by reformatting the Behave json to Cucumber json. ' + 'This fork contains a fix by lawnmowerlatte which has not been pulled into the main repo.', - url='https://github.com/behalf-oss/behave2cucumber', + url='https://github.com/lawnmowerlatte/behave2cucumber', author='Andrey Goldgamer, Zvika Messing', author_email='andrey.goldgamer@behalf.com, zvika@behalf.com ', From ff44fcb13ba66053f3cd092caed5d8ad6659d3fa Mon Sep 17 00:00:00 2001 From: lawnmowerlatte Date: Wed, 17 Jun 2020 14:14:23 -0400 Subject: [PATCH 4/5] Use different name for PyPI --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1e22237..7aa281e 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ here = path.abspath(path.dirname(__file__)) setup( - name='behave2cucumber', + name='behave2cucumber-lawnmowerlatte', version='1.0.4.1', From 39bcd628283f40b7774dc3cf091a07ad361a4902 Mon Sep 17 00:00:00 2001 From: lawnmowerlatte Date: Wed, 17 Jun 2020 15:28:41 -0400 Subject: [PATCH 5/5] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7aa281e..7881f21 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='behave2cucumber-lawnmowerlatte', - version='1.0.4.1', + version='1.0.4.2', description='Behave to Cucumber json converter (lawnmowerlatte fork)', long_description='This project helps solving the incompatibilty of Behave\'s genereated json reports '