Use vault-cli
in your tests¶
A vault
pytest fixture is available, but you may want to make sure that vault-cli
installs its testing extra dependencies:
$ pip install "vault-cli[testing]"
# conftest.py (for pytest)
from vault_cli.testing import vault
__all__ = ["vault"]
In your tests, use the vault
fixture. It has a db
parameter that you can use
to simulate existing secrets (keys are paths, values are secrets). When you use the
fixture, no call to a real vault will be issued, it’s all in memory. Of course, this
is only meant for tests, do NOT use this for real-life use cases.
# test_something.py
def test_bla(vault):
vault.db = {"a/b": {"c": "d"}}
assert vault.get_secret("a/b") == "c"