jeudi 11 mars 2021

Python assertEqual error "object has no attribute '_type_equality_funcs'"

I can't figure out why I'm having the following issue?

The code:

from unittest import TestCase


def increment_dictionary_values(d, i):
    for k, v in d.items():
        d[k] = v + i
    return d


class TestIncrementDictionaryValues(TestCase):
    def __init__(self):
        self.d = {'a': 1}

    def test_increment_dictionary_values(self, inc_val, test_val):
        dd = increment_dictionary_values(self.d, inc_val)
        self.assertEquals(dd['a'], test_val, msg="Good")


obj1 = TestIncrementDictionaryValues()
print(obj1.test_increment_dictionary_values(1,2))

The error iv got:

AttributeError: 'TestIncrementDictionaryValues' object has no attribute '_type_equality_funcs'

But if I remove the "init" method out of it and put the dictionary in the "TestIncrementDictionaryValues" method, than everything works ok.

Aucun commentaire:

Enregistrer un commentaire