Skip to content

Commit 9f57ed1

Browse files
Improve error message during assertion failure
1 parent 9fccffd commit 9f57ed1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tests/test_records.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,12 @@ def record_value_asserts(
388388
truncated_value = actual_value[: expected_value.size]
389389
assert numpy.array_equal(
390390
truncated_value, expected_value
391-
), "Arrays not equal: {} {}".format(actual_value, expected_value)
391+
), f"Arrays not equal: {actual_value} {expected_value}"
392392
assert type(actual_value) == expected_type
393393
else:
394394
assert actual_value == expected_value
395395
assert type(actual_value) == expected_type
396-
except Exception as e:
396+
except AssertionError as e:
397397
msg = (
398398
"Failed with parameters: "
399399
+ str(creation_func)
@@ -404,7 +404,11 @@ def record_value_asserts(
404404
+ ", "
405405
+ str(expected_type)
406406
)
407-
logging.error(msg, exc_info=e)
407+
# Add the parameters into the exception message. Seems to be the
408+
# cleanest place to add it, as doing a print() or a logging.error()
409+
# both cause the message to appear in a separate section of the pytest
410+
# results, which can be difficult to spot
411+
e.args += (msg,)
408412
raise e
409413

410414

0 commit comments

Comments
 (0)