report.py 785 B

123456789101112131415161718192021
  1. from __future__ import print_function
  2. from difflib import unified_diff
  3. def report_collection_diff(from_collection, to_collection, from_id, to_id):
  4. """Report the collected test difference between two nodes.
  5. :returns: detailed message describing the difference between the given
  6. collections, or None if they are equal.
  7. """
  8. if from_collection == to_collection:
  9. return None
  10. diff = unified_diff(from_collection, to_collection, fromfile=from_id, tofile=to_id)
  11. error_message = (
  12. u"Different tests were collected between {from_id} and {to_id}. "
  13. u"The difference is:\n"
  14. u"{diff}"
  15. ).format(from_id=from_id, to_id=to_id, diff="\n".join(diff))
  16. msg = "\n".join([x.rstrip() for x in error_message.split("\n")])
  17. return msg