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: Larger and/or configurable _MAX_LENGTH for unittest messages
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: 27432 Superseder:
Assigned To: Nosy List: maarten-treewalker, r.david.murray
Priority: normal Keywords:

Created on 2017-07-03 17:59 by maarten-treewalker, last changed 2022-04-11 14:58 by admin.

Messages (2)
msg297605 - (view) Author: Maarten ter Huurne (maarten-treewalker) Date: 2017-07-03 17:59
In a unit test for one of my projects I am comparing tree-structured objects using assertEqual(). Because there can be a few nested levels, the repr() string can exceed the _MAX_LENGTH which is just 80 characters. Not by much, but enough to get shortened and therefore requiring extra effort to figure out where the difference is.

I think it is useful to shorten the messages at some point, to avoid accidentally spamming the log with pages of output that no-one is going to read. However, 80 characters is a length that someone debugging a failing test case can easily deal with. So I think the limit could be set an order of magnitude larger.

Making the maximum length configurable would also solve the issue, but still it would be good to increase the default maximum then, in my opinion.

The discussion of #27432 mentions _MAX_LENGTH customization, but that issue is not primarily about _MAX_LENGTH.
msg297779 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-07-05 20:27
Yes, setting _MAX_LENGTH can be an independent feature request.  

The default will not be changed, however, since it is the most useful default given that assertEquals in general produces a much more useful diff output in addition to the one-line summary.  You might also/alternatively want to look in to providing your own assertEqual extension to produce a useful diff of your particular data structure.
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 75022
2017-07-05 20:27:37r.david.murraysetversions: + Python 3.7, - Python 3.4
nosy: + r.david.murray

messages: + msg297779

dependencies: + Support unittest assertion truncation of repr in error messages
2017-07-03 17:59:26maarten-treewalkercreate