I have a generator that yields a string
value and in my main app.py I utilize them.
Now I would like to create pytest and try to create a patch for this generator, I have no luck. Can anyone suggest a better working approach? I'm followed the StackOverflow previous question and solution but still didn't manage to get it done.
def test_index_route():
with patch("main._method") as mock_method:
mock_method.iter.return_value = iter(['1234'])
response = app.test_client().get('/')
assert response.status_code == 200
assert response.data.decode('utf-8') == 'hello world version 1234.'
this gives assert failed as
E assert "hello wo R...0854476448'>." == 'hello world version 1234.'
hello world version <MagicMock name='_version_if_file_exists().__next__()' id='140400854476448'>.