From 9cacc6c6164150cdf5961731f16caecc2de3d33b Mon Sep 17 00:00:00 2001 From: jitendracandela Date: Tue, 15 Oct 2024 16:43:05 +0530 Subject: [PATCH 1/6] Added Pretty-Print allure attachment for device statistics and reboot logs Signed-off-by: jitendracandela --- tests/conftest.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 10a27ddd64..0f205f0d22 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -521,20 +521,23 @@ def collect_logs(): query_ = f"?startDate={start_time}&endDate={end_time}" resp = get_target_object.controller_library_object.get_device_statistics_teardown(device_name, query=query_) if resp.status_code == 200: - allure.attach(body=str(resp.json()), name="device_statistics_per_test_case") + allure.attach(body=json.dumps(resp.json(), indent=4), name="device_statistics_per_test_case\n", + attachment_type=allure.attachment_type.JSON) else: logging.info("resp.status_code:- " + str(resp.status_code)) # Check reboot logs query_ = f"?logType=2&startDate={start_time}&endDate={end_time}" resp = get_target_object.controller_library_object.get_device_reboot_logs(device_name, query=query_) if resp.status_code == 200: - allure.attach(body=str(resp.json()), name="device_reboot_logs_per_test_case") + allure.attach(body=json.dumps(resp.json(), indent=4), name="device_reboot_logs_per_test_case\n", + attachment_type=allure.attachment_type.JSON) response = resp.json() # crash log validation if response["values"]: resp = get_target_object.controller_library_object.get_device_reboot_logs(device_name, query="?logType=2") - allure.attach(body=str(resp.json()), name="all_device_reboot_logs") + allure.attach(body=json.dumps(resp.json(), indent=4), name="all_device_reboot_logs\n", + attachment_type=allure.attachment_type.JSON) logging.info("Reboot detected on AP side") pytest.exit("Reboot detected on AP side") else: From e2e87f89ef4050264ee87f972c2b873950b37d80 Mon Sep 17 00:00:00 2001 From: jitendracandela Date: Thu, 17 Oct 2024 12:42:21 +0530 Subject: [PATCH 2/6] Added return code in pytest exit Signed-off-by: jitendracandela --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0f205f0d22..124739c1c4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -539,7 +539,7 @@ def collect_logs(): allure.attach(body=json.dumps(resp.json(), indent=4), name="all_device_reboot_logs\n", attachment_type=allure.attachment_type.JSON) logging.info("Reboot detected on AP side") - pytest.exit("Reboot detected on AP side") + pytest.exit("Reboot detected on AP side", 1) else: logging.info("resp.status_code:- " + str(resp.status_code)) From 2ba4ef0eb8f11c08c6e2aeb505127b4e5c719c98 Mon Sep 17 00:00:00 2001 From: jitendracandela Date: Fri, 18 Oct 2024 10:34:00 +0530 Subject: [PATCH 3/6] Modified pytest exit msg for the crash Signed-off-by: jitendracandela --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 124739c1c4..0de5ef3366 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -538,8 +538,8 @@ def collect_logs(): query="?logType=2") allure.attach(body=json.dumps(resp.json(), indent=4), name="all_device_reboot_logs\n", attachment_type=allure.attachment_type.JSON) - logging.info("Reboot detected on AP side") - pytest.exit("Reboot detected on AP side", 1) + logging.info("AP crashed during the test") + pytest.exit("AP crashed during the test", 1) else: logging.info("resp.status_code:- " + str(resp.status_code)) From a4a6f3f049b5d011766e18af0df445442cd69b3f Mon Sep 17 00:00:00 2001 From: jitendracandela Date: Fri, 18 Oct 2024 11:50:02 +0530 Subject: [PATCH 4/6] Added try and except for crash logs logic Signed-off-by: jitendracandela --- tests/conftest.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0de5ef3366..7e77fdd7d4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -538,8 +538,12 @@ def collect_logs(): query="?logType=2") allure.attach(body=json.dumps(resp.json(), indent=4), name="all_device_reboot_logs\n", attachment_type=allure.attachment_type.JSON) - logging.info("AP crashed during the test") - pytest.exit("AP crashed during the test", 1) + try: + pytest.fail("AP crashed during the test") + logging.info("AP crashed during the test") + except Exception as e: + logging.info("In the crash exception:- " + str(e)) + pytest.exit(1) else: logging.info("resp.status_code:- " + str(resp.status_code)) From 4cbc27b96cba7e5352a80b244123ef5c3a8b6a27 Mon Sep 17 00:00:00 2001 From: jitendracandela Date: Fri, 18 Oct 2024 14:54:48 +0530 Subject: [PATCH 5/6] Modified pytest exit code Signed-off-by: jitendracandela --- tests/conftest.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7e77fdd7d4..4b5e382442 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -538,12 +538,8 @@ def collect_logs(): query="?logType=2") allure.attach(body=json.dumps(resp.json(), indent=4), name="all_device_reboot_logs\n", attachment_type=allure.attachment_type.JSON) - try: - pytest.fail("AP crashed during the test") - logging.info("AP crashed during the test") - except Exception as e: - logging.info("In the crash exception:- " + str(e)) - pytest.exit(1) + logging.info("AP crashed during the test") + pytest.exit("AP crashed during the test", 2) else: logging.info("resp.status_code:- " + str(resp.status_code)) From c3bcdd44b0517b36edb9d3db9f987c21fdeb2d1a Mon Sep 17 00:00:00 2001 From: jitendracandela Date: Tue, 22 Oct 2024 10:46:22 +0530 Subject: [PATCH 6/6] Removed return code from pytest exit Signed-off-by: jitendracandela --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 4b5e382442..d19e8581a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -539,7 +539,7 @@ def collect_logs(): allure.attach(body=json.dumps(resp.json(), indent=4), name="all_device_reboot_logs\n", attachment_type=allure.attachment_type.JSON) logging.info("AP crashed during the test") - pytest.exit("AP crashed during the test", 2) + pytest.exit("AP crashed during the test") else: logging.info("resp.status_code:- " + str(resp.status_code))