Metadata-Version: 2.1
Name: pytest-kind
Version: 0.6.0
Summary: Kubernetes test support with KIND for pytest
Home-page: https://codeberg.org/hjacobs/pytest-kind
License: GPL-3.0+
Author: Henning Jacobs
Author-email: henning@jacobs1.de
Requires-Python: >=3.7,<4.0
Classifier: Framework :: Pytest
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Requires-Dist: pykube-ng (>=0.30.0,<0.31.0)
Project-URL: Repository, https://codeberg.org/hjacobs/pytest-kind
Description-Content-Type: text/markdown

# pytest-kind

![PyPI](https://img.shields.io/pypi/v/pytest-kind)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-kind)

Test your Python Kubernetes app/operator end-to-end with [kind](https://kind.sigs.k8s.io/) and [pytest](https://pytest.org).

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

```python
def test_kubernetes_version(kind_cluster):
    assert kind_cluster.api.version == ('1', '15')
```

To load your custom Docker image and apply deployment manifests:

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

