pytest-keyring


Namepytest-keyring JSON
Version 1.0.2 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_time2023-09-14 21:15:36
maintainer
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": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "keyring,pytest,pytest-plugin",
    "author": "Tom\u00e1s Far\u00edas Santana",
    "author_email": "tomas@tomasfarias.dev",
    "download_url": "https://files.pythonhosted.org/packages/57/24/550feb6976da6bf096691c3e19132caf323a6163f720e3498791514d8a7b/pytest_keyring-1.0.2.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.0.2",
    "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": "b51ae8af4ed4a5df188b7889c859a11401be33c40183bde3d42122587a7720ac",
                "md5": "9b724fc0b67f5427e7bfc9f0a58cdedf",
                "sha256": "57694d3f5586960c315e12a8de39b0641bf3ee7ddeb1aa41d4cbe59e3070004d"
            },
            "downloads": -1,
            "filename": "pytest_keyring-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9b724fc0b67f5427e7bfc9f0a58cdedf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4227,
            "upload_time": "2023-09-14T21:15:34",
            "upload_time_iso_8601": "2023-09-14T21:15:34.486355Z",
            "url": "https://files.pythonhosted.org/packages/b5/1a/e8af4ed4a5df188b7889c859a11401be33c40183bde3d42122587a7720ac/pytest_keyring-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5724550feb6976da6bf096691c3e19132caf323a6163f720e3498791514d8a7b",
                "md5": "913151949e16e523ee1853bac0f454cb",
                "sha256": "38a1af1062d799e0e28f1ddea8a3237db3fe249c82cbe6a45cd7633769d24387"
            },
            "downloads": -1,
            "filename": "pytest_keyring-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "913151949e16e523ee1853bac0f454cb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3597,
            "upload_time": "2023-09-14T21:15:36",
            "upload_time_iso_8601": "2023-09-14T21:15:36.106960Z",
            "url": "https://files.pythonhosted.org/packages/57/24/550feb6976da6bf096691c3e19132caf323a6163f720e3498791514d8a7b/pytest_keyring-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 21:15:36",
    "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: 0.11541s