@contextlib.contextmanager
def on_assert_failed_print_details(actual, expected):
 try:
  (yield)
 except AssertionError:
  diff = difflib.ndiff(expected.splitlines(), actual.splitlines())
  diff_text = u'\n'.join(diff)
  print(u'DIFF (+ ACTUAL, - EXPECTED):\n{0}\n'.format(diff_text))
  if DEBUG:
   print(u'expected:\n{0}\n'.format(expected))
   print(u'actual:\n{0}\n'.format(actual))
  raise

@ contextlib . contextmanager def on_assert_failed_print_details ( actual , expected ) : try : ( yield ) except AssertionError : diff = difflib . ndiff ( expected . splitlines ( ) , actual . splitlines ( ) ) diff_text = u'\n' . join ( diff ) print ( u'DIFF (+ ACTUAL, - EXPECTED):\n{0}\n' . format ( diff_text ) ) if DEBUG : print ( u'expected:\n{0}\n' . format ( expected ) ) print ( u'actual:\n{0}\n' . format ( actual ) ) raise
print text details in case of assertation failed errors .