I'm trying to mock fetchone/fetchall to return different data set for different cases within a suite but it seems the first mock is global and can't be overwritten. All I get for the subsequent tests is the same value.
The first test case which sets up the mock:
def test_rejected_scenario():
with mock.patch('psycopg2.connect') as mock_connect:
mock_con = mock_connect.return_value
mock_cursor = mock_con.cursor.return_value
mock_cursor.fetchall.return_value = REQUESTS
mock_cursor.fetchone.return_value = REQUESTS[0]
response = handler()
assert response["statusCode"] == 200
All the subsequent tests will get REQUESTS for fetchall() and REQUESTS[0] for fetchone() no matter how the mock is set up.
This question is about setting different return data set between test cases. Setting mock for individual case works for me.