report.py 785 Bytes
Newer Older
1
from __future__ import print_function
2 3 4 5 6 7 8 9 10 11 12 13
from difflib import unified_diff


def report_collection_diff(from_collection, to_collection, from_id, to_id):
    """Report the collected test difference between two nodes.

    :returns: detailed message describing the difference between the given
    collections, or None if they are equal.
    """
    if from_collection == to_collection:
        return None

14 15 16 17 18 19
    diff = unified_diff(from_collection, to_collection, fromfile=from_id, tofile=to_id)
    error_message = (
        u"Different tests were collected between {from_id} and {to_id}. "
        u"The difference is:\n"
        u"{diff}"
    ).format(from_id=from_id, to_id=to_id, diff="\n".join(diff))
20 21
    msg = "\n".join([x.rstrip() for x in error_message.split("\n")])
    return msg