我正在尝试编写测试pytest
以传递密码,getpass
但出现此错误:
OSError: reading from stdin while output is captured
这是我的功能:
def test_my_password_check(monkeypatch):
password = 'pytestpassword'
monkeypatch.setattr('getpass.getpass', lambda: password)
update_passwords()
assert keyring.get_password('testaddress', 'testusername') == password
我已经尝试过:
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
即使有from unittest.mock import patch
或update_passwords.getpass = lambda: password
所有这些都带有相同的错误。我错过了什么?谢谢!!