tests: use native pytest features for exception handling

Using `with pytest.raises` is better than open coding the equivalent
feature. Similarly, when a block is not expected to raise an exception,
let's just let it run outside of a `try` block and rely on the test
framework to report a possible failure when hitting an unhandled
exception.

Change-Id: Icb1bb83e649733b56fcdc9168cabf88c9cf8d478
This commit is contained in:
Jan Kundrát
2020-01-10 13:48:08 +01:00
committed by EstherLerouzic
parent c577a75725
commit fe811f725c

View File

@@ -309,26 +309,11 @@ def test_json_response_generation(xls_input, expected_response_file):
if i == 1:
my_rq = deepcopy(rqs[i])
my_rq.M = 0
error_handled = False
try:
temp_result = {
'response': Result_element(my_rq, pth, reversed_propagatedpths[i]).json}
except ServiceError:
error_handled = True
if not error_handled:
print('Service error with M=0 not correctly handled')
raise AssertionError()
error_handled = False
with pytest.raises(ServiceError):
Result_element(my_rq, pth, reversed_propagatedpths[i]).json
my_rq.blocking_reason = 'NO_SPECTRUM'
try:
temp_result = {
'response': Result_element(my_rq, pth, reversed_propagatedpths[i]).json}
print(temp_result)
except ServiceError:
error_handled = True
if error_handled:
print('Service error with NO_SPECTRUM blocking reason not correctly handled')
raise AssertionError()
Result_element(my_rq, pth, reversed_propagatedpths[i]).json
result.append(Result_element(rqs[i], pth, reversed_propagatedpths[i]))