I'm trying to write a test in pytest
to pass a password with getpass
but I'm getting this error:
OSError: reading from stdin while output is captured
here is my function:
def test_my_password_check(monkeypatch):
password = 'pytestpassword'
monkeypatch.setattr('getpass.getpass', lambda: password)
update_passwords()
assert keyring.get_password('testaddress', 'testusername') == password
I already try with:
import mock
@mock.patch("getpass.getpass")
def test_username_password(getpass):
password = 'pytestpassword'
getpass.return_value = "xxx"
update_passwords()
assert keyring.get_password('testaddress', 'testusername') == password
even with from unittest.mock import patch
or update_passwords.getpass = lambda: password
All of it with the same error. What am I missing? Thanks!!