I want to execute the code block under "if AssertionError:". But it is not working. My objective is for any Assertion error found for the previous assertion statements, I need to report the same in the log file. Where I have done wrong in the following code? I dont want to use try-except because using try except, I can make the above code work but the actual failures are not reported in the test report and its showing 100% pass even if there are assertion failures.
else:
assert context.json_response is not None
assert float(context.json_response[0]['base_premium']) > float(1)
assert float(context.json_response[0]['total_premium']) < float(1)
assert float(context.json_response[0]['tax']) > float(1)
print(context.json_response[0]["tax"])
if AssertionError:
json_data = context.payload
sys.stdout = open("OD_Plans.log", "a")
print("Test case failed due to assertion error")
print("Previous Policy Status=" + " " + status)
print("expiry date=" + " " + exp_date)
print("Owner=" + " " + owner)
print("Registration Date=" + " " + reg_date)
print("Manufacturing Year=" + " " + man_yr)
print("Veichle Maker=" + " " + vchl_make)
print("Maker Code=" + " " + vchl_code)
print(json.dumps(json_data, indent=2))