diff --git a/tests/unit/test_matchers.py b/tests/unit/test_matchers.py index 9889b4f..f7cfb9f 100644 --- a/tests/unit/test_matchers.py +++ b/tests/unit/test_matchers.py @@ -157,3 +157,18 @@ def test_metchers(): assert_matcher('port') assert_matcher('path') assert_matcher('query') + + +def test_get_assertion_message(): + assert matchers.get_assertion_message(None) == "" + assert matchers.get_assertion_message("") == "" + + +def test_get_assertion_message_with_details(): + assertion_msg = "q1=1 != q2=1" + expected = ( + "--------------- DETAILS ---------------\n" + "{}\n" + "----------------------------------------\n".format(assertion_msg) + ) + assert matchers.get_assertion_message(assertion_msg) == expected diff --git a/vcr/matchers.py b/vcr/matchers.py index ad04a45..784cfe4 100644 --- a/vcr/matchers.py +++ b/vcr/matchers.py @@ -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