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: unhelpful truncating of long strings.
Type: behavior Stage:
Components: Tests Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ella Sharakanski, cjw296, ezio.melotti, larry, michael.foord, ncoghlan, r.david.murray, rbcollins, serhiy.storchaka
Priority: normal Keywords: 3.4regression

Created on 2014-06-21 10:34 by cjw296, last changed 2022-04-11 14:58 by admin.

Messages (12)
msg221167 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2014-06-21 10:34
This code, prior to 3.4:

from testfixtures import Comparison as C

class AClass:
    def __init__(self,x,y=None):
        self.x = x
        if y:
            self.y = y
    def __repr__(self):
        return '<'+self.__class__.__name__+'>'

...

self.assertEqual(
    C('testfixtures.tests.test_comparison.AClass',
      y=5, z='missing'),
      AClass(1, 2))

Would give the following output in the failure message:

"""
<C(failed):testfixtures.tests.test_comparison.AClass>
  x:1 not in Comparison
  y:5 != 2
  z:'missing' not in other
</C> != <AClass>"
"""

Now, in 3.4, you get the (rather unhelpful):

"""
<C(failed):testfixtures.tests.test_com[79 chars] </C> != <AClass>
"""

It's particularly disappointing that there's no API (class attribute, etc) to control whether or not this new behaviour is enabled.

I believe the change that introduced this behaviour was in [issue18996]
msg221169 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-06-21 10:55
I'd say it's actually a bug that the new behaviour is triggering for inputs that aren't strings.
msg221170 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2014-06-21 10:56
Agreed, but even for strings, there really should be an API to control this...
msg221345 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2014-06-23 05:47
If I worked up a patch that:

- made sure this truncation wasn't used for non-strings

- added a class-attribute control for the truncation

Would it be well received?
msg221355 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-06-23 13:28
It's ultimately up to Michael as the module maintainer, but the class
attribute approach would match the way maxDiff works.
msg221356 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-06-23 13:39
Oh, one point - the "don't trigger on non-strings" could likely go in a bug
fix release for 3.4, but the flag to turn it off entirely would be a new
feature for 3.5.
msg221361 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2014-06-23 14:50
I agree that it looks like a bug that this behaviour is triggering for non-strings. There is separate code (which uses maxDiff) for comparing collections. 

Switching off the behaviour for 3.4 / 2.7 and a new class attribute for 3.5 is a good approach.
msg221397 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-06-24 06:33
Will be enough just to increase default maximal string length (_MAX_LENGTH) to say 200? I think we can do this even in a bug fix release for 3.4. We can also increase the number of tail characters (_MIN_BEGIN_LEN and _MIN_END_LEN).

I'm against the "don't trigger on non-strings", because the repr of non-strings can be pretty large.
msg221398 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2014-06-24 06:36
No, it would not be enough.

Please see the report above, the repr of non-strings may be large, but 
it's often intended that way and all of the string should be displayed.

It really is a shame that no API was provided to control this behaviour. 
I actually consider that a bug, Michael, could it be considered as such 
so that we can fix it in 3.4 rather than having to wait until 3.5 to fix 
the problem?
msg221473 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-24 16:06
For strings, all of the string was not displayed before, either, it was just truncated at the end only.  I'm surprised that that didn't apply to non-strings as well.  It's the diff output that is supposed to be the full text (if maxDiff is None), to my understanding, so it would make sense to me that either the whole output should be displayed if there is no diff output (and maxDiff is None?), or the reprs should be diffed.
msg341885 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2019-05-08 15:21
This bug is marked only for 3.4, and 3.4 is now EOL.  Either it should be relocated to an active version, or it should be marked wontfix.
msg357953 - (view) Author: Ella Sharakanski (Ella Sharakanski) Date: 2019-12-06 23:08
Any news on this? I also consider this a bug.
History
Date User Action Args
2022-04-11 14:58:05adminsetgithub: 66019
2019-12-06 23:08:38Ella Sharakanskisetnosy: + Ella Sharakanski
messages: + msg357953
2019-05-08 15:58:09cjw296setversions: + Python 3.7, Python 3.8, Python 3.9, - Python 3.4
2019-05-08 15:21:37larrysetnosy: + larry
messages: + msg341885
2014-10-28 23:07:31rbcollinssetnosy: + rbcollins
2014-06-24 16:06:13r.david.murraysetmessages: + msg221473
2014-06-24 06:36:16cjw296setmessages: + msg221398
2014-06-24 06:33:44serhiy.storchakasetmessages: + msg221397
2014-06-23 14:50:35michael.foordsetmessages: + msg221361
2014-06-23 13:39:30ncoghlansetmessages: + msg221356
2014-06-23 13:28:07ncoghlansetmessages: + msg221355
2014-06-23 05:47:57cjw296setmessages: + msg221345
2014-06-22 02:39:17r.david.murraysetnosy: + r.david.murray, serhiy.storchaka
2014-06-21 20:03:12ned.deilysetnosy: + ezio.melotti, michael.foord
2014-06-21 10:56:29cjw296setmessages: + msg221170
2014-06-21 10:55:29ncoghlansetnosy: + ncoghlan
messages: + msg221169
2014-06-21 10:34:46cjw296create