Python - unittests: compare some objects using their attributes instead if they are really the same object?
<p>I have method that sets data into class attribute.</p>

<p>So let say I run:</p>

<pre><code>self._set_data(some_data)
print self._data
</code></pre>

<p>It prints me this information:</p>

<pre><code>{'c2': {
    'column': 1, 
    'style': &lt;xlwt.Style.XFStyle object at 0x7f4668a18dd0&gt;, 
    'value': u'Argentina', 'row': 2}, 
'c1': {
    'column': 0, 
    'style': &lt;xlwt.Style.XFStyle object at 0x7f4668a18dd0&gt;, 
    'value': 'C is not Python', 'row': 0}}
</code></pre>

<p>So every key except <code>style</code> has simple data, so there is no problem checking what is expected when running unittests. But the problem I see with <code>style</code> key, it returns instantiated <code>xlwt</code> module's style object. Now even if I would create "same" style using same values to <code>__init__</code> it, unittest would still fail, because it would compare objects, so it would be different object. Does python standard unittest suite have something like that? Or I need extend unittests suite, so it would compare that specific object differently somehow?</p>

<p>In your tests you can create a mock style object which is initialized with the expected values, then compare it's <code>__dict__</code> attribute to the <code>__dict__</code> attribute of the tested style object.</p>

<pre><code>if mock_style.__dict__ == tested_style.__dict__ :
    print('The styles are set correctly.')
</code></pre>

python python-2.7 object python-unittest xlwt