Skip to main content

A Pytest plugin to access the system's keyring to provide credentials for tests

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_keyring-1.1.2.tar.gz (86.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_keyring-1.1.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_keyring-1.1.2.tar.gz.

File metadata

  • Download URL: pytest_keyring-1.1.2.tar.gz
  • Upload date:
  • Size: 86.9 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for pytest_keyring-1.1.2.tar.gz
Algorithm Hash digest
SHA256 ea7c8a79dfe63de406dc36e68074ab0b0392af5dd1560df3a66d7e52c379e3ec
MD5 e15aae6cbe15f8dc40c72b8b7eb12991
BLAKE2b-256 0d2239c1fc5f6f811d5c0b33d890a40a3eb6f8791fc97e3572d05971e5416b5c

See more details on using hashes here.

File details

Details for the file pytest_keyring-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: pytest_keyring-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for pytest_keyring-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9dd00d33c02881cb61b885cb168ccffb3575c23306876896e7671f29081381c9
MD5 2afb723d80c5fe4617c87a8d314833b2
BLAKE2b-256 3058dd98e84d2b085e8ed8a7022995b1b90c3f9ee3ae8a3eca4909fc84ec2cfa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page