This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unittest: use ascii() instead of repr() to display values on error
Type: Stage:
Components: Library (Lib), Unicode Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: michael.foord, vstinner
Priority: normal Keywords: patch

Created on 2010-10-21 00:14 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
unittest_ascii.patch vstinner, 2010-10-21 00:14
Messages (3)
msg119248 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-10-21 00:14
On a failure, unittest does its best to display values. But sometimes, the output doesn't help me. Example:

FAIL: test_listdir (test.test_pep277.UnicodeFileTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/db3l/buildarea/3.x.bolen-tiger/build/Lib/test/test_pep277.py", line 157, in test_listdir
    self.assertEqual(sf0, sf2)
AssertionError: Items in the first set but not the second:
'@test_18608_tmp/ ̈́ΎΫ'
'@test_18608_tmp/ẛ῁῍῎῏῝῞῟῭'
Items in the second set but not the first:
'@test_18608_tmp/ ̈́ΥΎ̈'
'@test_18608_tmp/ẛ῁῍῎᾿῾῾῾῁̀́͂̀'
'@test_18608_tmp/΅ϒϓ̈'

This is a test on unicode filenames. I would prefer to see non-ASCII characters as \xHH or \uXXXX than strange characters or boxes.

Do you think that it is a good idea to replace calls to repr() by ascii() in the unittest library?

In Python2, repr(unicode) escapes all non-ASCII characters. But in Python3, only control characters and surrogates are escaped. So the output depends on the terminal encoding.

Write non-ASCII characters in a backtrace may also raise a new error if the terminal is unable to a character. Raise an error while printing an error is just horrible :-)

--

Attached patch is a try to replace repr() by ascii() in the unittest module. But I don't know this library, so don't trust the patch :-)
msg119531 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-10-24 21:05
Closed with r85829: patch test_pep277 instead of unittest.
msg119532 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-10-25 01:11
Although this is still a real issue for other users of unittest. If I get time to think about it properly I may reopen.
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54370
2010-10-25 01:11:34michael.foordsetmessages: + msg119532
2010-10-24 21:05:33vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg119531
2010-10-21 12:16:57eric.araujosetnosy: + michael.foord
2010-10-21 00:14:03vstinnercreate