Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,20 @@ def test_warns_for_empty_password(
assert auth.Resolver(config, auth.CredentialInput()).password == password

assert caplog.messages[0].startswith(warning)


def test_log_exception_on_keyring_failure(config, monkeypatch, caplog):
class FailKeyring:
@staticmethod
def get_credential(system, username):
import os

# Let's simulate the error that occurred
# in https://github.com/pypa/twine/issues/889
os.environ["HOME"]

monkeypatch.setattr(auth, "keyring", FailKeyring())

assert not auth.Resolver(config, auth.CredentialInput()).get_username_from_keyring()

assert "KeyError: 'HOME'" in caplog.text and caplog.messages[0] == "'HOME'"
4 changes: 2 additions & 2 deletions twine/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_username_from_keyring(self) -> Optional[str]:
# To support keyring prior to 15.2
pass
except Exception as exc:
logger.warning(str(exc))
logger.exception(exc)
return None

def get_password_from_keyring(self) -> Optional[str]:
Expand All @@ -73,7 +73,7 @@ def get_password_from_keyring(self) -> Optional[str]:
logger.info("Querying keyring for password")
return cast(str, keyring.get_password(system, username))
except Exception as exc:
logger.warning(str(exc))
logger.exception(exc)
return None

def username_from_keyring_or_prompt(self) -> str:
Expand Down