I'm currently having trouble unit testing a function that has multiple prints on multiple rows:
def state_game(grid, score):
print(grid[0])
print(grid[1])
print(grid[2])
print(grid[3])
print(f"Your score is {score}")
return('------------')
What I'm trying to do is test for each row of print whether the line printed on python terminal is correct. So far I've tried this to capture what's printed on terminal :
import unittest
from unittest.mock import patch
"defining grid"
"defining score"
def test_state_game(self, mock_print):
state_game(grid, score)
mock_print.assert_called_with(grid[0])
mock_print.assert_called_with(grid[1])
mock_print.assert_called_with(grid[2])
mock_print.assert_called_with(grid[3])
mock_print.assert_called_with(f"Your score is {score}")
The problem is it seems that when it first tests whether grid[0] is printed on terminal, the test fails showing that expected is grid[0] when "Your score is {score}" has been printed (i.e. the last print of the state_game function). Any idea ?