def test_dish_ages(self, mocker): # mocker.spy wraps Bacteria.ages() so that we can get # a call count (and more information if we wanted) mocker.spy(Bacteria, 'ages') n_a, n_b = 10, 20 d = Dish(n_a, n_b) d.aging() assert Bacteria.ages.call_count == n_a + n_b
def test_dish_ages_callers(self, mocker): # mocker.spy wraps Bacteria.ages() so that we can get # a list of arguments for all calls to ages() mocker.spy(Bacteria, 'ages') n_a, n_b = 10, 20 d = Dish(n_a, n_b) d.aging() # get list of arguments for each call # each element of the list is a tuple: (positional_args, kwargs) # ages() takes only self as positional arg, so we are only # interested in those args = Bacteria.ages.call_args_list pos_args, kwargs = zip(*args) # pos_args should be n_a + n_b different bacteria objects # use set() to eliminate duplicates assert len(set(pos_args)) == len(pos_args)