From dc86ea7574cf622925a680c81768d2e33abb0dab Mon Sep 17 00:00:00 2001 From: Dhrumil Mistry <56185972+dmdhrumilmistry@users.noreply.github.com> Date: Thu, 4 Apr 2024 19:52:09 +0530 Subject: [PATCH] do not store errored requests into output file --- src/offat/__main__.py | 8 ++++++++ src/offat/report/generator.py | 11 ++++++++++- src/offat/tester/tester_utils.py | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/offat/__main__.py b/src/offat/__main__.py index 9836e69..e404941 100644 --- a/src/offat/__main__.py +++ b/src/offat/__main__.py @@ -119,6 +119,13 @@ def start(): action='store_true', help='Enable SSL Verification', ) + parser.add_argument( + '-cf', + '--capture-failed', + dest='capture_failed', + action='store_true', + help='Captures failed requests due to any exceptions into output file', + ) args = parser.parse_args() # convert req headers str to dict @@ -146,6 +153,7 @@ def start(): test_data_config=test_data_config, proxies=args.proxies_list, ssl=args.ssl, + capture_failed=args.capture_failed, ) diff --git a/src/offat/report/generator.py b/src/offat/report/generator.py index fdec7f3..a94b0b7 100644 --- a/src/offat/report/generator.py +++ b/src/offat/report/generator.py @@ -120,12 +120,21 @@ def save_report(report_path: str | None, report_file_content: str | Table | None @staticmethod def generate_report( - results: list[dict], report_format: str | None, report_path: str | None + results: list[dict], + report_format: str | None, + report_path: str | None, + capture_failed: bool = False, ): """main function used to generate report""" if report_path: report_format = report_path.split('.')[-1] + # do not store errored results if `capture_failed` is False + if not capture_failed: + results = list( + filter(lambda result: result.get('error', True) == False, results) + ) + formatted_results = ReportGenerator.handle_report_format( results=results, report_format=report_format ) diff --git a/src/offat/tester/tester_utils.py b/src/offat/tester/tester_utils.py index cd0ff98..c71a530 100644 --- a/src/offat/tester/tester_utils.py +++ b/src/offat/tester/tester_utils.py @@ -119,6 +119,7 @@ def generate_and_run_tests( proxies: list[str] | None = None, test_data_config: dict | None = None, ssl: bool = False, + capture_failed: bool = False, ): ''' Generates and runs tests for provied OAS/Swagger file.