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 aconftest.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
Use Incremental Tests
Use Incremental Tests
Mark test classes with
@pytest.mark.incremental to skip subsequent tests when a test fails:Use Descriptive Test Names
Use Descriptive Test Names
Prefix tests with numbers to ensure execution order:
Clean Up Resources
Clean Up Resources
Always clean up resources in fixtures or tests:
Test Error Conditions
Test Error Conditions
Test both success and failure scenarios:
Use Class-scoped Fixtures
Use Class-scoped Fixtures
Share expensive setup across tests:
Running Tests
- Run All Tests
- Run Specific Test File
- Run Specific Test Class
- Run With Verbosity
- Run With Coverage
Debugging Tests
Print Debug Information
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