2

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!!

virtualdvid
  • 2,323
  • 3
  • 14
  • 32
  • 1
    I had faced a similar issue due to keeping `import pdb; pdb.set_trace()` inside one of Django's source files. – Shiva Oct 31 '19 at 14:27

0 Answers0