Skip to main content
Learn how to write comprehensive tests for your Kubernetes and OpenShift applications using the fake client and pytest.

Testing Architecture

The openshift-python-wrapper provides a complete testing framework built on:

Fake Client

Mock Kubernetes API for testing without a cluster

Pytest

Powerful testing framework with fixtures and markers

Incremental Tests

Skip dependent tests when previous tests fail

Setting Up Test Fixtures

Basic Fixture Configuration

Create a conftest.py file with shared fixtures:
conftest.py

Resource Fixtures

Create reusable resource fixtures:
conftest.py

Basic Test Patterns

CRUD Operations

Test the complete lifecycle of a resource:
test_namespace.py
The @pytest.mark.incremental marker ensures that if a test fails, subsequent tests in the class are skipped.

Testing Pods

test_pod.py

Advanced Test Patterns

Testing Resource Conditions

Test resources that may not be immediately ready:
test_conditions.py

Testing Events

test_events.py

Testing Resource Lists

Test creating and managing multiple resources:
test_resource_lists.py

Testing Namespaced Resource Lists

test_namespaced_lists.py

Context Manager Testing

Resource Context Manager

Test automatic cleanup with context managers:
test_context_manager.py

Testing Teardown Errors

test_teardown_errors.py

Testing Complete Applications

Test full application deployments:
test_application.py

Testing Best Practices

Mark test classes with @pytest.mark.incremental to skip subsequent tests when a test fails:
Prefix tests with numbers to ensure execution order:
Always clean up resources in fixtures or tests:
Test both success and failure scenarios:
Share expensive setup across tests:

Running Tests

Debugging Tests

Use pytest.set_trace()

Next Steps

Fake Client

Learn more about the fake Kubernetes client

Class Generator

Generate wrapper classes for testing

Examples

Explore more testing examples

API Reference

Complete API documentation