Skip to content

Commit

Permalink
Add an ability to delete skipped test results
Browse files Browse the repository at this point in the history
To remove skipped tests was added --remove-skipped flag to publish
function.

Change-Id: I2048c18927193512f48feb9324f7d410f94dbe4e
  • Loading branch information
ibumarskov committed Oct 21, 2020
1 parent 694449c commit 090a11f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Set the TestRail parameters before using the script:
-c TR_CONF Set configuration for test entry (Test Run). Example:
-c "{'Operating Systems':'Ubuntu 18.04'}"
--remove-untested Remove untested cases from Test Run
--remove-skipped Remove skipped cases from Test Run
--result-attrs TR_RESULT_ATTRS
Custom result attributes
--result-map TR_RESULT_MAP
Expand Down
8 changes: 7 additions & 1 deletion testrail_reporter/cmd/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def publish(args, config):
milestone=args.tr_milestone,
configuration=tr_conf,
update_existing=True,
remove_untested=args.remove_untested)
remove_untested=args.remove_untested,
remove_skipped=args.remove_skipped)


def update_suite(args, config):
Expand Down Expand Up @@ -174,6 +175,11 @@ def main():
default=False,
help='Remove untested cases from Test Run'
)
parser_b.add_argument(
'--remove-skipped', dest='remove_skipped', action="store_true",
default=False,
help='Remove skipped cases from Test Run'
)
parser_b.add_argument(
'--result-attrs', dest='tr_result_attrs',
default=None,
Expand Down
19 changes: 13 additions & 6 deletions testrail_reporter/lib/testrailreporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def update_test_suite(self, name, tc_list):

def publish_results(self, results, plan_name, suite_name, run_name,
milestone=None, configuration=None,
update_existing=False, remove_untested=False):
update_existing=False, remove_untested=False,
remove_skipped=False):
suite = self.project.get_suite_by_name(suite_name)
plans_list = self.project.get_plans_project()
plan = None
Expand Down Expand Up @@ -227,19 +228,25 @@ def publish_results(self, results, plan_name, suite_name, run_name,
self.project.add_results(run['id'], {'results': results['results']})
LOG.info("Results were uploaded.")

rm_statuses = []
if remove_skipped:
rm_statuses.append("skipped")
if remove_untested:
LOG.info("Remove untested tests.")
untested_tests = self.get_untested_tests(run['id'])
case_ids = list(map(lambda a: a['case_id'], untested_tests))
rm_statuses.append("untested")
if rm_statuses:
LOG.info("Remove tests with statuses: {}".format(rm_statuses))
rm_tests = self.get_tests_by_status(run['id'], rm_statuses)
case_ids = list(map(lambda a: a['case_id'], rm_tests))
data = {'include_all': False,
'case_ids': case_ids}
if configuration:
data["config_ids"] = conf_ids
self.project.update_plan_entry(plan['id'], plan_entry['id'], data)
LOG.info("Completed.")

def get_untested_tests(self, run_id):
def get_tests_by_status(self, run_id, statuses):
status_ids = list(map(lambda a: a['id'], self.project.statuses))
status_ids.remove(self.project.get_status_by_label("untested"))
for status in statuses:
status_ids.remove(self.project.get_status_by_label(status))
tests_filter = self.project.get_tests_filter(status_id=status_ids)
return self.project.get_tests(run_id, filter=tests_filter)

0 comments on commit 090a11f

Please sign in to comment.