Skip to main content

Kubernetes test support with KIND for pytest

Project description

pytest-kind

PyPI PyPI - Python Version

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:

import requests
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


Download files

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

Source Distribution

pytest-kind-0.6.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

pytest_kind-0.6.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-kind-0.6.0.tar.gz.

File metadata

  • Download URL: pytest-kind-0.6.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.3 Linux/4.15.0-58-generic

File hashes

Hashes for pytest-kind-0.6.0.tar.gz
Algorithm Hash digest
SHA256 480c3e0be2a0b91a02391ff5c523278e12053d2b6a8c24d713819da8e0542474
MD5 a6c3a27a20f3510301f13c41bc61b9f2
BLAKE2b-256 952412c573e83e0936195604a5babc641ee6190803f152dd4209b7911aba4ef1

See more details on using hashes here.

File details

Details for the file pytest_kind-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_kind-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.3 Linux/4.15.0-58-generic

File hashes

Hashes for pytest_kind-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98b9d8dcfb818be05078d111923d62be7acedcef8dff142e06aa12324d6f14b2
MD5 1c12191f5766dbac4df9e39759f03fd0
BLAKE2b-256 a1474a3c3aa7ede06cd07fe84735b4e7a1b71aa6b7f937c2b90cb3c6d8d2eb42

See more details on using hashes here.

Supported by

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