Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x pytest中的getpass返回OSError:捕获输出时从stdin读取_Python 3.x_Pytest_Getpass - Fatal编程技术网

Python 3.x pytest中的getpass返回OSError:捕获输出时从stdin读取

Python 3.x pytest中的getpass返回OSError:捕获输出时从stdin读取,python-3.x,pytest,getpass,Python 3.x,Pytest,Getpass,我正试图在pytest中编写一个测试,以通过getpass传递密码,但出现以下错误: OSError: reading from stdin while output is captured 以下是我的功能: def test_my_password_check(monkeypatch): password = 'pytestpassword' monkeypatch.setattr('getpass.getpass', lambda: password) upd

我正试图在
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
即使使用unittest.mock导入补丁中的
更新\u passwords.getpass=lambda:password


所有这些都有相同的错误。我错过了什么?谢谢

由于保留
导入pdb,我曾面临类似的问题;pdb.set_trace()
在Django的一个源文件中。由于保持
import pdb;pdb.set_trace()
在Django的一个源文件中。