From 82dbb0b0c368253fd41a9a6fc0cab309e4b22404 Mon Sep 17 00:00:00 2001 From: Jitendrakumar Kushavah <78074038+jitendracandela@users.noreply.github.com> Date: Mon, 4 Nov 2024 20:33:02 +0530 Subject: [PATCH] Added pretty print in the reboot logs and device statistics (#1006) * Added Pretty-Print allure attachment for device statistics and reboot logs Signed-off-by: jitendracandela * Added return code in pytest exit Signed-off-by: jitendracandela * Modified pytest exit msg for the crash Signed-off-by: jitendracandela * Added try and except for crash logs logic Signed-off-by: jitendracandela * Modified pytest exit code Signed-off-by: jitendracandela * Removed return code from pytest exit Signed-off-by: jitendracandela --------- Signed-off-by: jitendracandela --- tests/conftest.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 10a27ddd64..d19e8581a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -521,22 +521,25 @@ 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") - logging.info("Reboot detected on AP side") - pytest.exit("Reboot detected on AP side") + 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") else: logging.info("resp.status_code:- " + str(resp.status_code))