pytest-keyring


Namepytest-keyring JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/tomasfarias/pytest-keyring
SummaryA Pytest plugin to access the system's keyring to provide credentials for tests
upload_time2024-12-08 18:08:02
maintainerNone
docs_urlNone
authorTomás Farías Santana
requires_python>=3.8
licenseMIT
keywords keyring pytest pytest-plugin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-keyring

Pytest plugin to access any configured keyring using the [`keyring`](https://pypi.org/project/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:

```bash
python -m pip install pytest-keyring
```

Python versions 3.8 to 3.12 are 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:

```python
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`:

```python
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:

```bash
pytest --keyring-backend=keyring.backends.null.Keyring
```

Causes all credentials and passwords to be `None`:

```python
def test_with_null_backend(credential_postgres_dbuser, password_postgres_dbuser):
    assert credential_postgres_dbuser is None
    assert password_postgres_dbuser is None
    ...
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tomasfarias/pytest-keyring",
    "name": "pytest-keyring",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "keyring, pytest, pytest-plugin",
    "author": "Tom\u00e1s Far\u00edas Santana",
    "author_email": "tomas@tomasfarias.dev",
    "download_url": "https://files.pythonhosted.org/packages/7d/12/08451c2a0758d094bb5dc115ddbb26805321eae39a65b567df9716cc8a39/pytest_keyring-1.1.0.tar.gz",
    "platform": null,
    "description": "# pytest-keyring\n\nPytest plugin to access any configured keyring using the [`keyring`](https://pypi.org/project/keyring/) package.\n\n## Motivation\n\nFrequently, 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.\n\n## Installation\n\nInstall with:\n\n```bash\npython -m pip install pytest-keyring\n```\n\nPython versions 3.8 to 3.12 are supported.\n\n## Usage\n\n### Accessing credentials in keyring\n\nAny 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:\n\n```python\ndef test_with_database(credential_postgres_dbuser):\n    client = connect(\n        username=credential_postgres_dbuser.username,\n        password=credential_postgres_dbuser.password\n    )\n    ...\n```\n\nWhen 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`:\n\n```python\nkeyring.get_credential(\"postgres\", \"dbuser\")\n```\n\n### Configuring a keyring backend\n\nThe `--keyring-backend` configuration flag can be used to specify a keyring backend. For example, setting the null keyring backend:\n\n```bash\npytest --keyring-backend=keyring.backends.null.Keyring\n```\n\nCauses all credentials and passwords to be `None`:\n\n```python\ndef test_with_null_backend(credential_postgres_dbuser, password_postgres_dbuser):\n    assert credential_postgres_dbuser is None\n    assert password_postgres_dbuser is None\n    ...\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Pytest plugin to access the system's keyring to provide credentials for tests",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/tomasfarias/pytest-keyring",
        "Repository": "https://github.com/tomasfarias/pytest-keyring"
    },
    "split_keywords": [
        "keyring",
        " pytest",
        " pytest-plugin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e25eb731ed09cc88af56c346b8f7eb81326857d02ed3abbfb2b4d585a557e429",
                "md5": "601efe04faf90d2e4dd5a4b20759a659",
                "sha256": "0acd7ce8e8ec0c7af38c03406aa616a636f4f9c088d5ce91e25a57b6f8863693"
            },
            "downloads": -1,
            "filename": "pytest_keyring-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "601efe04faf90d2e4dd5a4b20759a659",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4884,
            "upload_time": "2024-12-08T18:08:01",
            "upload_time_iso_8601": "2024-12-08T18:08:01.353235Z",
            "url": "https://files.pythonhosted.org/packages/e2/5e/b731ed09cc88af56c346b8f7eb81326857d02ed3abbfb2b4d585a557e429/pytest_keyring-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d1208451c2a0758d094bb5dc115ddbb26805321eae39a65b567df9716cc8a39",
                "md5": "7637a104d4e7b5b7ac1c9441537689c9",
                "sha256": "cb468d4d04552b599a2f081ea84b9a8d06a39c7b49563fcb7f4bee93c126e439"
            },
            "downloads": -1,
            "filename": "pytest_keyring-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7637a104d4e7b5b7ac1c9441537689c9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4245,
            "upload_time": "2024-12-08T18:08:02",
            "upload_time_iso_8601": "2024-12-08T18:08:02.992922Z",
            "url": "https://files.pythonhosted.org/packages/7d/12/08451c2a0758d094bb5dc115ddbb26805321eae39a65b567df9716cc8a39/pytest_keyring-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-08 18:08:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tomasfarias",
    "github_project": "pytest-keyring",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "pytest-keyring"
}
        
Elapsed time: 9.05769s