1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

add function to format the assertion message

This function is used to prettify the assertion message when a matcher failed and return an assertion error.
This commit is contained in:
Arthur Hamon
2019-06-12 11:51:00 +02:00
parent 728dc71a35
commit de244a968f
2 changed files with 35 additions and 0 deletions

View File

@@ -99,3 +99,23 @@ def requests_match(r1, r2, matchers):
matches = [(m(r1, r2), m) for m in matchers]
_log_matches(r1, r2, matches)
return all(m[0] for m in matches)
def get_assertion_message(assertion_details, **format_options):
"""
Get a detailed message about the failing matcher.
"""
msg = ""
if assertion_details:
separator = format_options.get("separator", "-")
title = format_options.get("title", " DETAILS ")
nb_separator = format_options.get("nb_separator", 40)
first_title_line = (
separator * ((nb_separator - len(title)) // 2)
+ title
+ separator * ((nb_separator - len(title)) // 2)
)
msg += "{}\n{}\n{}\n".format(
first_title_line, str(assertion_details), separator * nb_separator
)
return msg