I have a module called backend that has the population.py Python file. The population.get_distinct_persons() stores the distinct person ids into a global set:
distinct_persons = set()
def get_distinct_persons(population):
for person in population.persons:
distinct_persons.add(person.person_id)
if __name__ == '__main__':
population = Population()
person1 = Person(1)
population.persons.append(person1)
person2 = Person(2)
population.persons.append(person2)
get_distinct_persons(population)
I need to write a unit test for function get_distinct_persons that checks if the expected and actual distinct_persons are equal. I have seen this post Modifying global variables in Python unittest framework and know that Python mocking module can probably let me do this, but have not yet found a way that works. Please share your ideas and thoughts. Thanks!