Last active
June 2, 2020 20:52
-
-
Save rnrbarbosa/e11ea2b7d75b32dec0195ce9363e39be to your computer and use it in GitHub Desktop.
PYTEST EXAMPLE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scenario: Kubernetes Pods | |
Given Kubernetes Cluster | |
When List All Pods | |
Then All Pods are on Running or Completed state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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