When using nose 1.2.1 with Python 3.3.0, I sometimes get an error message similar to the following one
======================================================================
FAIL: maxdiff2.test_equal
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
File "/Users/loic/cmrsj/Calculus_II/scrap/maxdiff2.py", line 32, in test_equal
assert_equal(str1, str2)
AssertionError: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a
diam lectus.\n [truncated]... != 'Suspendisse lectus leo, consectetur in tempor sit
amet, placerat quis neque.\nE [truncated]...
Diff is 1780 characters long. Set self.maxDiff to None to see it.
----------------------------------------------------------------------
Ran 1 test in 0.064s
FAILED (failures=1)
In many situations, to figure out what the error really is, I need to see the full diff output. However, I have no idea of how to set that self.maxDiff
. Googling for nose and maxDiff does not help. With the same version of nose on Python 2.7.1 the full diff is printed to screen.
Here is a simple script that generates the error above when run with nosetests-3.3
:
from nose.tools import assert_equal
def test_equal():
str1 = """\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.
Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec
consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero
egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem
lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida
lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor.
Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim
sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in
urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam
pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris
vitae nisi at sem facilisis semper ac in est."""
str2 = """\
Suspendisse lectus leo, consectetur in tempor sit amet, placerat quis neque.
Etiam luctus porttitor lorem, sed suscipit est rutrum non. Curabitur lobortis
nisl a enim congue semper. Aenean commodo ultrices imperdiet. Vestibulum ut
justo vel sapien venenatis tincidunt. Phasellus eget dolor sit amet ipsum
dapibus condimentum vitae quis lectus. Aliquam ut massa in turpis dapibus
convallis. Praesent elit lacus, vestibulum at malesuada et, ornare et est. Ut
augue nunc, sodales ut euismod non, adipiscing vitae orci. Mauris ut placerat
justo. Mauris in ultricies enim. Quisque nec est eleifend nulla ultrices
egestas quis ut quam. Donec sollicitudin lectus a mauris pulvinar id aliquam
urna cursus. Cras quis ligula sem, vel elementum mi. Phasellus non ullamcorper
urna."""
assert_equal(str1, str2)
This works in python 2.7:
It'll set the default maxDiff for all TestCase instances, including the one that assert_equals and friends are attached to.
Here you have it (what google told me):
I had the same problem in Python 3 (from reading the other answers here) and using
im_class
did not work. The snippet below works in Python 3 (cf. How to find instance of a bound method in Python?):As @Louis commented, the convenience functions are bound methods on a
Dummy
instance. They all seem to be on the same instance, so changing this for e.g.assert_equal
will change it forassert_dict_equal
et cetera. From the Python docs,__self__
is available from Python 2.6 and forward.You set
maxDiff
toNone
.But you will have to actually use a
unittest.TestCase
for your tests for that to work.This shold work.In python 2.7.3, nose 1.3.0, doing the following is working for me: