Spy assertion always 0

25 Views Asked by At

I am trying to test the following function using a spy on the row creation function. Even If I can print the row function and see that it is being called the assert always fails with AssertionError call_count == 0. The mocks are being implemented properly, as the function does not error out. However, the spy is not working.

  def deamp_tester(model_a_id: int) -> str | Response:
    batch = db.session.query(ModelA).filter_by(id=model_a_id).first_or_404()
    list_a = get_list_dict_a()
    list_b = get_list_dict_b()
    data_frame_rows = []
    for i, plate in enumerate(batch.plates):
      chose_input_plate = i % 2
      tables: list[PlatePosition] = db.session.query(Table).filter_by(position_id=plate.id).all()
      for position in tables:
          wall_position = position.y_coordinate + str(position.x_coordinate)
          balls = controls.pop()
          for type, destination_well in balls.items():
              row = create_df_row(
                 ......
               )
            data_frame_rows.append(row)


@auto_login(username="test.admin")
def test_process_batch_calls_deamp_row_correctly(client, mocker: 
  MockFixture, mock_db_query_return_values):
  mocker.patch("app.extensions.db.session.query", 
  side_effect=mock_db_query_return_values)

  mocker.patch("util.create_csv_filename", return_value="test.csv")

  mock_create_deamp_worklist_row= mocker.patch("app.util.create_df_row")

  deamp_tester(model_a_id=1)
  
  assert mock_create_deamp_worklist_row.call_count == 3

Also tried as spy:

mock_create_deamp_worklist_row= mocker.spy(util, "create_df_row")
0

There are 0 best solutions below