Kubernetes test support with KIND for pytest
Project description
pytest-kind
Test your Python Kubernetes app/operator end-to-end with kind and pytest.
pytest-kind
is a plugin for pytest which provides the kind_cluster
fixture.
The fixture will install kind, create a cluster, and provide convenience functionality such as port forwarding.
Usage
Install pytest-kind
via pip or via poetry, e.g.:
poetry add --dev pytest-kind
Write your pytest functions and use the provided kind_cluster
fixture, e.g.:
def test_kubernetes_version(kind_cluster):
assert kind_cluster.api.version == ('1', '15')
To load your custom Docker image and apply deployment manifests:
from pykube import Pod
def test_myapp(kind_cluster):
kind_cluster.load_docker_image("myapp")
kind_cluster.kubectl("apply", "-f", "deployment.yaml")
kind_cluster.kubectl("rollout", "status", "deployment/myapp")
# using Pykube to query pods
for pod in Pod.objects(kind_cluster.api).filter(selector="app=myapp"):
assert "Sucessfully started" in pod.logs()
with kind_cluster.port_forward("service/myapp", 80) as port:
r = requests.get(f"http://localhost:{port}/hello/world")
r.raise_for_status()
assert r.text == "Hello world!"
See the examples
directory for sample projects.
Pytest Options
The kind cluster name can be set via the --cluster-name
CLI option.
The kind cluster is deleted after each pytest session, you can keep the cluster by passing --keep-cluster
to pytest.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_kind-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3adbc0ca0a51b3886344a675d3b5ec56f1bde30b2c8254bc3cef9add1a86852f |
|
MD5 | e7ac1d91141c56dd98e70ac860fae203 |
|
BLAKE2b-256 | c3231896bdd5504b514fd62dfda230806f8ec871d48fc9fc0c8b4ba268e9f6f3 |