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

前端 未结 6 548
广开言路
广开言路 2020-12-13 23:12

When using nose 1.2.1 with Python 3.3.0, I sometimes get an error message similar to the following one

======================================================         


        
相关标签:
6条回答
  • 2020-12-13 23:29

    In python 2.7.3, nose 1.3.0, doing the following is working for me:

    assert_equal.im_class.maxDiff = None
    assert_equal(huge_thing, other_huge_thing)
    
    0 讨论(0)
  • 2020-12-13 23:44

    Here you have it (what google told me):

    # http://pdf2djvu.googlecode.com/hg/tests/common.py
    try:
        from nose.tools import assert_multi_line_equal
    except ImportError:
        assert_multi_line_equal = assert_equal
    else:
        assert_multi_line_equal.im_class.maxDiff = None
    
    0 讨论(0)
  • 2020-12-13 23:46

    This works in python 2.7:

        from unittest import TestCase
        TestCase.maxDiff = None
    

    It'll set the default maxDiff for all TestCase instances, including the one that assert_equals and friends are attached to.

    0 讨论(0)
  • 2020-12-13 23:49

    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?):

    assert_equal.__self__.maxDiff = None
    

    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 for assert_dict_equal et cetera. From the Python docs, __self__ is available from Python 2.6 and forward.

    0 讨论(0)
  • 2020-12-13 23:49

    I recently ran into this problem .... I was forcing a MS type line ending ....

    MSstr="""hi\r
    there\r"""
    expected="""hi
    there"""
    
    self.assertEqual(MSsrt, expected) 
    

    That crashed with the horrible errors other are using.

    In PyCharm it said the files were identical !!

    I removed the \r - no more crash and tests now pass.

    Hope that saves someone the 2 hours it cost me.

    0 讨论(0)
  • 2020-12-13 23:51

    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>
    
    0 讨论(0)
提交回复
热议问题