I am having trouble figuring out why the first of these statements is OK and the second is causing an error.
subject_list = [Subject("A"), Subject("B"), Subject("C")] subject_set = set() subject_set.add(Subject("A")) subject_set.add(Subject("B")) subject_set.add(Subject("C")) self.assertIn(Subject("A"), subject_list) self.assertIn(Subject("A"), subject_set)
Here is the error:
Traceback (most recent call last): File "C:\Users\...\testSubject.py", line 34, in testIn self.assertIn(Subject("A"), subject_set) AssertionError: <Subject: A> not found in set([<Subject: B>, <Subject: C>, <Subject: A>])
The equality test in the Subject class is just self.name == other.name , and in another UnitTest I check that Subject("A") == Subject("A") . I really canβt understand why the topic is on the list and not on the set. Ideally, I would like the theme to be in both.
python list set member
rtclay
source share