mardi 16 février 2021

mock patch multiple user inputs in sequence

similar questions have been asked many times, but I can't seem to figure out this simple test I am trying to build: I would like to first supply a "y", and then a "n" to a complex function requiring user input (i.e. it requires two inputs in sequence). This is my attempt - the with statement doesn't advance the iterator, but I don't know how I would implement patched input otherwise.

import mock

m = mock.Mock()
m.side_effect = ["y","n"]
    
@pytest.fixture(scope="module")
def test_my_complex_function():
    with mock.patch('builtins.input', return_value=m()):
        out = my_complex_function(some_args)
    return out

Aucun commentaire:

Enregistrer un commentaire