-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
35 lines (24 loc) · 888 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import keyring
import pytest
from keyring.errors import PasswordDeleteError
os.environ['USER'] = 'ipython_secrets_PYTEST_USER'
class MockKeyringBackend(keyring.backend.KeyringBackend):
_passwords = dict()
def clear(self):
self._passwords.clear()
def get_password(self, servicename, username):
return self._passwords.get((servicename, username))
def set_password(self, servicename, username, password):
self._passwords[(servicename, username)] = password
def delete_password(self, servicename, username):
try:
self._passwords.pop((servicename, username))
except IndexError:
raise PasswordDeleteError()
mockKeyringBackend = MockKeyringBackend()
keyring.set_keyring(mockKeyringBackend)
@pytest.fixture
def keyring_backend():
mockKeyringBackend.clear()
return mockKeyringBackend