pytest-keyring
Pytest plugin to access any configured keyring using the keyring package.
Motivation
Frequently, tests require access to services, like databases, REST APIs, or blob storages. These services are sometimes hard or impossibel to mock or reproduce in a test environment. In particular, functional or end-to-end tests will be inclined to interact with real instances of these services. Accessing these services can require credentials, and using the keyring can be an alternative to populating CI environment variables with credentials.
Installation
Install with:
python -m pip install pytest-keyring
Any python version newer than 3.8 is supported.
Usage
Accessing credentials in keyring
Any test arguments whose names match the prefixes configured by --keyring-password-prefix and --keyring-credential-prefix ("password" and "credential" by default) will be replaced by the corresponding password or credential, respectively:
def test_with_database(credential_postgres_dbuser):
client = connect(
username=credential_postgres_dbuser.username,
password=credential_postgres_dbuser.password
)
...
When collecting the test, the credential_postgres_dbuser instructs pytest-keyring to fetch the credential for the "postgres" service and the "dbuser" username, by making the following call to keyring.get_credential:
keyring.get_credential("postgres", "dbuser")
Configuring a keyring backend
The --keyring-backend configuration flag can be used to specify a keyring backend. For example, setting the null keyring backend:
pytest --keyring-backend=keyring.backends.null.Keyring
Causes all credentials and passwords to be None:
def test_with_null_backend(credential_postgres_dbuser, password_postgres_dbuser):
assert credential_postgres_dbuser is None
assert password_postgres_dbuser is None
...
Release files for pytest-keyring 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_keyring-1.1.3.tar.gz | 86.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_keyring-1.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 91.9 kB
Release files / pytest_keyring-1.1.3.tar.gz
| Download URL | pytest_keyring-1.1.3.tar.gz |
|---|---|
| Size | 86.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18edfa8b1e1270759a47ff6ba550caa124773c415311ef9199a350f20edbd95d
|
|
BLAKE2b-256 checksum How to use checksums |
b7820d8b43c12e9efc7a511f74b5234c77dbcb207648b6a823ab0d7e5b1c01e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pytest_keyring-1.1.3-py3-none-any.whl
| Download URL | pytest_keyring-1.1.3-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8dfde146fdb3f252d649ccc0aa052080f31a8d2e996c5c8c7726ad28360ec6f3
|
|
BLAKE2b-256 checksum How to use checksums |
730157cec49cb9599797cb15ef24b08b6e4774bb1be40ccfb609b10745276ca8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|