Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

python - How to set self.maxDiff in nose to get full diff output?

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.
 [truncated]... != 'Suspendisse lectus leo, consectetur in tempor sit
amet, placerat quis neque.
E [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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You set maxDiff to None.

But you will have to actually use a unittest.TestCase for your tests for that to work. This should work.

class MyTest(unittest.TestCase):

    maxDiff = None

    def test_diff(self):
          <your test here>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...