Let's say I have a module named foo with a class Bar. Bar has a classwide counter attribute that allows me to track the order which instances were created. foo looks like this:
from itertools import count
class Bar:
class_count = count(0)
def __init__(self):
self.id = self.class_count.next()
Now I have a test file where I am testing the various functionalities of Bar. I am unsure of how to test this id attribute, because the other unittests are creating instances of Bar and so I don't know what the given id of a Bar instance should be. Furthermore, this behavior of my class means that my unittests are independent of each other, which is undesirable. How should I structure my unittests so the tests are independent of each other?