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

喜欢而已 提交于 2019-11-28 22:17:06
vicvicvic

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.

Lennart Regebro

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>

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.

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

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)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!