Skip to content

Instantly share code, notes, and snippets.

@rnrbarbosa
Last active June 2, 2020 20:52
Show Gist options
  • Save rnrbarbosa/e11ea2b7d75b32dec0195ce9363e39be to your computer and use it in GitHub Desktop.
Save rnrbarbosa/e11ea2b7d75b32dec0195ce9363e39be to your computer and use it in GitHub Desktop.
PYTEST EXAMPLE
Scenario: Kubernetes Pods
Given Kubernetes Cluster
When List All Pods
Then All Pods are on Running or Completed state
import pytest
from pytest_bdd import scenario, given, when, then
from kubernetes import client, config
@scenario('pods.feature', 'Kubernetes Pods')
def kubernetes():
pass
@pytest.fixture
def pods():
config.load_kube_config()
v1 = client.CoreV1Api()
pods = v1.list_pod_for_all_namespaces(watch=False)
return pods
@given("Kubernetes Cluster")
def cluster():
pass
@when("List All Pods")
def list_pods():
pass
@then("All Pods are on Running or Completed state")
def test_pods(pods):
for p in pods.items:
print(p.metadata.name)
assert p.status.phase in ['Running','Completed']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment